<?php
/*
 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
 * Copyright (C) 2002-2012 The Nucleus Group
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * (see nucleus/documentation/index.html#license for more info)
 */
/**
 * This class contains the functions that get called by using
 * the special tags in the skins
 *
 * The allowed tags for a type of skinpart are defined by the
 * SKIN::getAllowedActionsForType($type) method
 *
 * @license http://nucleuscms.org/license.txt GNU General Public License
 * @copyright Copyright (C) 2002-2012 The Nucleus Group
 * @version $Id: skinableACTIONS.php 164 2012-02-13 13:32:00Z shizuki17xx $
 * @version $NucleusJP: ACTIONS.php,v 1.8 2007/04/19 06:05:55 kimitake Exp $
 */

class skinableACTIONS extends BaseActions
{

    // part of the skin currently being parsed ('index', 'item', 'archive',
    // 'archivelist', 'member', 'search', 'error', 'imagepopup')
    var $skintype;

    // contains an assoc array with parameters that need to be included when
    // generating links to items/archives/... (e.g. catid)
    var $linkparams;

    // reference to the skin object for which a part is being parsed
    var $skin;

    // used when including templated forms from the include/ dir. The $formdata var
    // contains the values to fill out in there (assoc array name -> value)
    var $formdata;

    // filled out with the number of displayed items after calling one of the
    // (other)blog/(other)searchresults skinvars.
    var $amountfound;

    public $objAdmin;

    public $newPlugCandidates;

    /**
     * Constructor for a new ACTIONS object
     */
    function __construct($type, $skin, $objAdmin)
    {
        // call constructor of superclass first
        $this->BaseActions();
        $this->skintype = $type;
        $this->objAdmin = $objAdmin;
    }

    /**
     *  Set the skin
     */
    function setSkin(&$skin) {
        $this->skin =& $skin;
    }

    /**
     *  Set the parser
     */
    function setParser(&$parser) {
        $this->parser =& $parser;
    }

    /**
     * Checks conditions for if statements
     *
     * @param string $field type of <%if%>
     * @param string $name property of field
     * @param string $value value of property
     */
    function checkCondition($field, $name='', $value = '') {
        global $CONF, $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;

        $condition = 0;
        switch($field) {
            case 'category':
                if (!$blog) {
                    if ($blogid) {
                        global $manager;
                        $blog =& $manager->getBlog($blogid);
                    } elseif ($catid) {
                        $blogid = getBlogIDFromCatID($catid);
                        global $manager;
                        $blog =& $manager->getBlog($blogid);
                    } elseif (intRequestVar('catid')) {
                        $catid = intRequestVar('catid');
                        $blogid = getBlogIDFromCatID($catid);
                        global $manager;
                        $blog =& $manager->getBlog($blogid);
                    } else {
                        return;
                    }
                }
                $condition = ($blog && $this->_ifCategory($name,$value));
                break;
            case 'blogsetting':
                $condition = ($blog && ($blog->getSetting($name) == $value));
                break;
            case 'loggedin':
                $condition = $member->isLoggedIn();
                break;
            case 'onteam':
                $condition = $member->isLoggedIn() && $this->_ifOnTeam($name);
                break;
            case 'admin':
                $condition = $member->isLoggedIn() && $this->_ifAdmin($name);
                break;
            case 'superadmin':
                $condition = $member->isLoggedIn() && $member->isAdmin();
                break;
            case 'allowloginedit':
                $condition = $member->isLoggedIn() && ($CONF['AllowLoginEdit'] || $member->isAdmin());
                break;
            case 'nextitem':
                $condition = ($itemidnext != '');
                break;
            case 'previtem':
                $condition = ($itemidprev != '');
                break;
            case 'archiveprevexists':
                $condition = ($archiveprevexists == true);
                break;
            case 'archivenextexists':
                $condition = ($archivenextexists == true);
                break;
            case 'skintype':
                $condition = (($name == $this->skintype) || ($name == requestVar('action')));
                break;
            case 'hasplugin':
                $condition = $this->_ifHasPlugin($name, $value);
                break;
            case 'adminaction':
                $condition = ($this->objAdmin->action == $name);
                break;
            case 'adminoldaction':
                $condition = ($this->objAdmin->action == $name);
                break;
            case 'addresschange':
                $condition = ($this->_ifAddresscange());
                break;
            case 'bechangepass':
                $condition = ($this->_beChangePassword());
                break;
            case 'skincandidates':
                $condition = ($this->_ifSkincandidates());
                break;
            case 'nameclashes':
                $condition = requestVar('nameclashes');
                break;
            case 'existsnewplugin':
                $condition = ($this->_existsNewPlugin());
                break;
            default:
                $condition = $manager->pluginInstalled('NP_' . $field) && $this->_ifPlugin($field, $name, $value);
                break;
        }
        return $condition;
    }

    /**
     *  hasplugin,PlugName
     *     -> checks if plugin exists
     *  hasplugin,PlugName,OptionName
     *     -> checks if the option OptionName from plugin PlugName is not set to 'no'
     *  hasplugin,PlugName,OptionName=value
     *     -> checks if the option OptionName from plugin PlugName is set to value
     */
    function _ifHasPlugin($name, $value) {
        global $manager;
        $condition = false;
        // (pluginInstalled method won't write a message in the actionlog on failure)
        if ($manager->pluginInstalled('NP_'.$name)) {
            $plugin =& $manager->getPlugin('NP_' . $name);
            if ($plugin != NULL) {
                if ($value == "") {
                    $condition = true;
                } else {
                    list($name2, $value2) = explode('=', $value, 2);
                    if ($value2 == "" && $plugin->getOption($name2) != 'no') {
                        $condition = true;
                    } else if ($plugin->getOption($name2) == $value2) {
                        $condition = true;
                    }
                }
            }
        }
        return $condition;
    }

    function _beChangePassword()
    {
        return intRequestVar('bNeedsPasswordChange');
    }

    /**
     * Checks if a plugin exists and call its doIf function
     */
    function _ifSkincandidates()
    {
        global $DIR_SKINS;
        $candidates = SKINIMPORT::searchForCandidates($DIR_SKINS);
        return count($candidates) > 0;
    }

    /**
     * Checks if a plugin exists and call its doIf function
     */
    function _ifPlugin($name, $key = '', $value = '') {
        global $manager;

        $plugin =& $manager->getPlugin('NP_' . $name);
        if (!$plugin) return;

        $params = func_get_args();
        array_shift($params);

        return call_user_func_array(array(&$plugin, 'doIf'), $params);
    }

    /**
     *  Different checks for a category
     */
    function _ifCategory($name = '', $value='') {
        global $blog, $catid;

        // when no parameter is defined, just check if a category is selected
        if (($name != 'catname' && $name != 'catid') || ($value == ''))
            return $blog->isValidCategory($catid);

        // check category name
        if ($name == 'catname') {
            $value = $blog->getCategoryIdFromName($value);
            if ($value == $catid)
                return $blog->isValidCategory($catid);
        }

        // check category id
        if (($name == 'catid') && ($value == $catid))
            return $blog->isValidCategory($catid);

        return false;
    }

    /**
     *  Checks if a member is on the team of a blog and return his rights
     */
    function _ifOnTeam($blogName = '') {
        global $blog, $member, $manager;

        // when no blog found
        if (($blogName == '') && (!is_object($blog)))
            return 0;

        // explicit blog selection
        if ($blogName != '')
            $blogid = getBlogIDFromName($blogName);

        if (($blogName == '') || !$manager->existsBlogID($blogid))
            // use current blog
            $blogid = $blog->getID();

        return $member->teamRights($blogid);
    }

    /**
     *  Checks if a member is admin of a blog
     */
    function _ifAdmin($blogName = '') {
        global $blog, $member, $manager;

        // when no blog found
        if (($blogName == '') && (!is_object($blog)))
            return 0;

        // explicit blog selection
        if ($blogName != '')
            $blogid = getBlogIDFromName($blogName);

        if (($blogName == '') || !$manager->existsBlogID($blogid))
            // use current blog
            $blogid = $blog->getID();

        return $member->isBlogAdmin($blogid);
    }

    /**
     * Check e-Mail address is changed
     */
    function _ifAddresscange()
    {
        $key = $this->objAdmin->sessionVar($CONF['CookiePrefix'] . 'ackey');
        if (!$key) {
            return false;
        }
        $info = MEMBER::getActivationInfo($key);
        if (!$info) {
            return false;
        }
        $mem  = MEMBER::createFromId($info->vmember);
        if (!$mem) {
            return false;
        }
        if ($info->vtype == 'addresschange') {
            return true;
        }
        return false;
    }
    
    /**
     * returns either
     *      - a raw link (html/xml encoded) when no linktext is provided
     *      - a (x)html <a href... link when a text is present (text htmlencoded)
     */
    function _link($url, $linktext = '')
    {
        $u = ENTITY::hsc($url, ENT_QUOTES);
        $u = preg_replace("/&amp;amp;/",'&amp;',$u); // fix URLs that already had encoded ampersands
        if ($linktext != '')
            $l = '<a href="' . $u .'">'.ENTITY::hsc($linktext, ENT_QUOTES).'</a>';
        else
            $l = $u;
        return $l;
    }

    /**
     *  Creates an item link and if no id is given a todaylink 
     */
    function _itemlink($id, $linktext = '') {
        global $CONF;
        if ($id)
            echo $this->_link(createItemLink($id, $this->linkparams), $linktext);
        else
            $this->parse_todaylink($linktext);
    }

    /**
     * Helper function that sets the category that a blog will need to use
     *
     * @param $blog
     *     An object of the blog class, passed by reference (we want to make changes to it)
     * @param $catname
     *     The name of the category to use
     */
    function _setBlogCategory(&$blog, $catname) {
        global $catid;
        if ($catname != '')
            $blog->setSelectedCategoryByName($catname);
        else
            $blog->setSelectedCategory($catid);
    }

    /**
     * Parse skinvar addpopupcode
     * Code that opens a bookmarklet in an popup window
     */
    function parse_addpopupcode() {
        echo "if (event &amp;&amp; event.preventDefault) event.preventDefault();winbm=window.open(this.href,'nucleusbm','scrollbars=no,width=600,height=550,left=10,top=10,status=no,resizable=yes');winbm.focus();return false;";
    }

    /**
     * Parse skinvar adminurl
     * (shortcut for admin url)  
     */
    function parse_adminurl() {
        $this->parse_sitevar('adminurl');
    }

    /**
     * Parse skinvar blogsetting
     */
    function parse_blogsetting($which)
    {
        echo $this->parse_getblogsetting($which);
    }

    /**
     * Parse skinvar getblogsetting
     */
    function parse_getblogsetting($which) {
        global $blog;
        if ($blog) {
            $b =& $blog;
        } elseif ($bid = intRequestVar('blogid')) {
            global $manager;
            $b = $manager->getBlog($bid);
        } else {
            return;
        }
        switch($which) {
            case 'id':
                return ENTITY::hsc($b->getID(), ENT_QUOTES);
                break;
            case 'url':
                return ENTITY::hsc($b->getURL(), ENT_QUOTES);
                break;
            case 'name':
                return ENTITY::hsc($b->getName(), ENT_QUOTES);
                break;
            case 'desc':
                return ENTITY::hsc($b->getDescription(), ENT_QUOTES);
                break;
            case 'short':
                return ENTITY::hsc($b->getShortName(), ENT_QUOTES);
                break;
            case 'notifyaddress':
                return ENTITY::hsc($b->getNotifyAddress(), ENT_QUOTES);
                break;
            case 'maxcomments':
                return ENTITY::hsc($b->getMaxComments(), ENT_QUOTES);
                break;
            case 'updatefile':
                return ENTITY::hsc($b->getUpdateFile(), ENT_QUOTES);
                break;
            case 'timeoffset':
                return ENTITY::hsc($b->getTimeOffset(), ENT_QUOTES);
                break;
        }
    }

    /**
     * Parse callback
     */
    function parse_callback($eventName, $type)
    {
        global $manager;
        $manager->notify(
            $eventName,
            array(
                'type' => $type
            )
        );
    }

    /**
     * Parse skinvar category
     */
    function parse_category($type = 'name')
    {
        echo $this->parse_getcategory($type);
    }

    /**
     * Parse skinvar getcategory
     */
    function parse_getcategory($type = 'name')
    {
        global $catid, $blog;
        if (!$blog) {
            if ($blogid) {
                global $manager;
                $blog =& $manager->getBlog($blogid);
            } elseif ($catid) {
                $blogid = getBlogIDFromCatID($catid);
                global $manager;
                $blog =& $manager->getBlog($blogid);
            } elseif (intRequestVar('catid')) {
                $catid = intRequestVar('catid');
                $blogid = getBlogIDFromCatID($catid);
                global $manager;
                $blog =& $manager->getBlog($blogid);
            } else {
                return;
            }
        }
        if (!$blog) {
            return false;
        }
        
        if (!$blog->isValidCategory($catid)) {
            return false;
        }

        switch($type) {
            case 'name':
                return $blog->getCategoryName($catid);
                break;
            case 'desc':
                return $blog->getCategoryDesc($catid);
                break;
            case 'id':
                return $catid;
                break;
        }
    }

    /**
     * Parse skinvar charset
     */
    function parse_charset()
    {
        echo _CHARSET;
    }

    /**
     * Parse errordiv
     */
    function parse_errordiv()
    {
        global $errormessage;
        if ($errormessage)
            echo '<div class="error">' . ENTITY::hsc($errormessage, ENT_QUOTES) . '</div>';
    }
    
    /**
     * Parse skinvar errormessage
     */
    function parse_errormessage()
    {
        global $errormessage;
        echo $errormessage;
    }
    
    /**
     * Parse formdata
     */
    function parse_formdata($what)
    {
        echo $this->formdata[$what];
    }

    /**
     * Parse skinvar image
     */
    function parse_image($what = 'imgtag') {
        global $CONF;

        $imagetext  = ENTITY::hsc(requestVar('imagetext'), ENT_QUOTES);
        $imagepopup = requestVar('imagepopup');
        $width      = intRequestVar('width');
        $height     = intRequestVar('height');
        $fullurl    = ENTITY::hsc($CONF['MediaURL'] . $imagepopup, ENT_QUOTES);

        switch($what) {
            case 'url':
                echo $fullurl;
                break;
            case 'width':
                echo $width;
                break;
            case 'height':
                echo $height;
                break;
            case 'caption':
            case 'text':
                echo $imagetext;
                break;
            case 'imgtag':
            default:
                $tag = '<img src="%s" width="%d" height="%d" alt="%s" title="%s" />';
                echo sprintf($tag, $fullurl, $width, $height, $imagetext, $imagetext);
                break;
        }
    }

    /**
     * Inserts an url relative to the skindir (useful when doing import/export)
     *
     * e.g. <skinfile(default/myfile.sth)>
     */
    function parse_skinfile($filename)
    {
        $base = NP_SkinableAdmin::getAdminSkinURL();
        $pref = PARSER::getProperty('IncludePrefix');
        echo $base . $pref . $filename;
    }

    /**
     * Parse skinvar imagetext
     */
    function parse_imagetext()
    {
        $this->parse_image('imagetext');
    }

    /**
     * Parse skinvar itemid
     */
    function parse_itemid(){
        global $itemid;
        echo intval($itemid);
    }
    
    /**
     * Parse skinvar itemlink
     */
    function parse_itemlink($linktext = '')
    {
        global $itemid;
        $this->_itemlink($itemid, $linktext);
    }

    /**
     * Parse itemtitle
     */
    function parse_itemtitle($format = '') {
        global $manager, $itemid;
        $item =& $manager->getItem($itemid,0,0);

        switch ($format) {
            case 'xml':
                echo stringToXML ($item['title']);
                break;
            case 'attribute':
                echo stringToAttribute ($item['title']);
                break;
            case 'raw':
                echo $item['title'];
                break;
            default:
                echo ENTITY::hsc(strip_tags($item['title']), ENT_QUOTES);
                break;
        }
    }

    /**
     * Parse skinvar customhelplink
     */
    function parse_customhelplink($topic, $tplName = '', $url = '', $iconURL = '', $alt = '', $title = '', $onclick = '')
    {
        $this->customHelp($topic, $url, $iconURL);
    }

    // shows a link to custom help file
    private function customHelp($id, $tplName = '', $url = '', $iconURL = '', $alt = '', $title = '', $onclick = '')
    {
        echo self::customHelpHtml($id, $tplName, $url, $iconURL, $alt, $title, $onclick);
    }

    static function customHelpHtml($id, $tplName = '', $url = '', $iconURL = '', $alt = '', $title = '', $onclick = '')
    {
        $templates = array();
        if ($tplName) {
            $templates = skinableTEMPLATE::read($tplName);
        }
        if (isset($templates['ADMIN_CUSTOMHELPLINK_ICON']) && !empty($templates['ADMIN_CUSTOMHELPLINK_ICON'])) {
            $template = $templates['ADMIN_CUSTOMHELPLINK_ICON'];
        } else  {
            $template = '<img src="<%iconurl%>" <%width%><%height%>alt="<%alt%>" title="<%title%>" /></a>';
        }
        if (empty($iconURL)) {
            global $CONF;
            $iconURL = $CONF['AdminURL'] . 'documentation/icon-help.gif';
        }
        if (function_exists('getimagesize')) {
            $size   = getimagesize($iconURL);
            $width  = 'width="'  . $size[0] . '" ';
            $height = 'height="' . $size[1] . '" ';
        }
        $data = array(
            'iconurl' => $iconURL,
            'width'   => $width,
            'height'  => $height,
            'alt'     => (isset($alt) && !empty($alt))     ? $alt   : _HELP_TT,
            'title'   => (isset($title) && !empty($title)) ? $title : _HELP_TT,
        );
        $icon = TEMPLATE::fill($template, $data);
        $help = self::customHelplink($id, $tplName, $url, $title, $onclick);
        return $help . $icon;
    }

    static function customHelplink($id, $tplName = '', $url = '', $title = '', $onclick = '')
    {
        $templates = array();
        if ($tplName) {
            $templates = skinableTEMPLATE::read($tplName);
        }
        if (isset($templates['ADMIN_CUSTOMHELPLINK_ANCHOR']) && !empty($templates['ADMIN_CUSTOMHELPLINK_ANCHOR'])) {
            $template = $templates['ADMIN_CUSTOMHELPLINK_ANCHOR'];
        } else {
            $template = '<a href="<%helpurl%>#<%helptarget%>" title="<%title%>" <%onclick%>>';
        }
        if (empty($url)) {
            global $CONF;
            $url    = $CONF['AdminURL'] . 'documentation/customHelp.html';
        }
        if (empty($onclick)) {
            $onclick = 'onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); return help(this.href);"';
        } elseif (preg_match('/^onclick/', $onclick)) {
            $onclick = $onclick;
        } else {
            $onclick = 'onclick="' . $onclick . '"';
        }
        $data = array(
            'helpurl'    => $url,
            'helptarget' => $id,
            'onclick'    => $onclick,
            'title'      => (isset($title) && !empty($title)) ? $title : _HELP_TT,
        );
        return TEMPLATE::fill($template, $data);
    }

    /**
     * Parse skinvar defaultadminskintypes
     */
    function parse_defaultadminskintypes($tabindex, $templateName = '')
    {
        $templates = array();
        if ($templateName) {
            $templates = skinableTEMPLATE::read($templateName);
        }

        $types   = skinableSKIN::getAdminskinDefaultTypeFriendlyNames();
        ksort($types);
        if (isset($templates['ADMINSKINTYPELIST_HEAD']) && !empty($templates['ADMINSKINTYPELIST_HEAD'])) {
            $template['head'] = $templates['ADMINSKINTYPELIST_HEAD'];
        } else {
            $template['head'] = "        <ul>\n";
        }
        echo $template['head'];

        if (isset($templates['ADMINSKINTYPELIST_BODY']) && !empty($templates['ADMINSKINTYPELIST_BODY'])) {
            $template['body'] = $templates['ADMINSKINTYPELIST_BODY'];
        } else {
            $template['body'] = '            <li><a tabindex="<%tabindex%>" href="index.php?action=adminskinedittype&amp;skinid=<%skinid%>&amp;type=<%skintype%>">'
                              . "<%name%></a> <%help%></li>\n";
        }
        $handler = new skinableACTIONS('template', $template, new ADMIN);
        $parser  = new PARSER(skinableACTIONS::getDefinedActions(), $handler);

        foreach($types as $type => $fName) {
            $helplink = $this->customHelpHtml('skinpart' . $type, $templateName);
            $data = array(
                'tabindex' => $tabindex,
                'skintype' => $type,
                'name'     => $fName,
                'help'     => $helplink,
                'skinid'   => intrequestVar('skinid'),
            );
            $templateBody = skinableTEMPLATE::fill($template['body'], $data);
            $parser->parse($templateBody);
            $tabindex++;
        }
        if (isset($templates['ADMINSKINTYPELIST_FOOT']) && !empty($templates['ADMINSKINTYPELIST_FOOT'])) {
            $template['foot'] = $templates['ADMINSKINTYPELIST_FOOT'];
        } else {
            $template['foot'] = "        </ul>\n";
        }
        echo $template['foot'];
    }

    /**
     * Parse skinvar loginform
     */
    function parse_loginform() {
        global $member, $CONF;
        if (!$member->isLoggedIn()) {
            $filename = 'loginform-notloggedin';
            $this->formdata = array();
        } else {
            $filename = 'loginform-loggedin';
            $this->formdata = array(
                'membername' => $member->getDisplayName(),
            );
        }
        $this->doForm($filename);
    }

    /**
     * Parse skinvar member
     * (includes a member info thingie)  
     */
    function parse_member($what)
    {
        echo $this->parse_getmember($what);
    }

    /**
     * Parse skinvar getmember
     * (includes a member info thingie)  
     */
    function parse_getmember($what) {
        global $memberinfo, $member;
        // 1. only allow the member-details-page specific variables on member pages
        if ($this->skintype == 'member') {
            switch($what) {
                case 'name':
                    return ENTITY::hsc($memberinfo->getDisplayName(), ENT_QUOTES);
                    break;
                case 'realname':
                    return ENTITY::hsc($memberinfo->getRealName(), ENT_QUOTES);
                    break;
                case 'notes':
                    return ENTITY::hsc($memberinfo->getNotes(), ENT_QUOTES);
                    break;
                case 'url':
                    return ENTITY::hsc($memberinfo->getURL(), ENT_QUOTES);
                    break;
                case 'email':
                    return ENTITY::hsc($memberinfo->getEmail(), ENT_QUOTES);
                    break;
                case 'id':
                    return ENTITY::hsc($memberinfo->getID(), ENT_QUOTES);
                    break;
            }
        }
        // 2. the next bunch of options is available everywhere, as long as the user is logged in
        if ($member->isLoggedIn()){
            switch($what) {
                case 'yourname':
                    return $member->getDisplayName();
                    break;
                case 'yourrealname':
                    return $member->getRealName();
                    break;
                case 'yournotes':
                    return $member->getNotes();
                    break;
                case 'yoururl':
                    return $member->getURL();
                    break;
                case 'youremail':
                    return $member->getEmail();
                    break;
                case 'yourid':
                    return $member->getID();
                    break;
            }
        }

    }

    /**
     * Parse skinvar nucleusbutton
     */
    function parse_nucleusbutton($imgurl = '', $imgwidth = '85', $imgheight = '31', $templateName = '') {
        global $CONF;
        if ($imgurl == '') {
            $imgurl = $CONF['AdminURL'] . 'nucleus.gif';
        } else if (PARSER::getProperty('IncludeMode') == 'skindir') {
            // when skindit IncludeMode is used: start from skindir
            $imgurl = $CONF['SkinsURL'] . PARSER::getProperty('IncludePrefix') . $imgurl;
        }
        $this->formdata = array(
            'imgurl'    => $imgurl,
            'imgwidth'  => $imgwidth,
            'imgheight' => $imgheight,
        );
        $this->doForm('nucleusbutton', $templateName);
    }

    /**
      * Executes a plugin skinvar
      *
      * @param pluginName name of plugin (without the NP_)
      *
      * extra parameters can be added
      */
    function parse_plugin($pluginName) {
        global $manager;
        // should be already tested from the parser (PARSER.php)
        // only continue when the plugin is really installed
        /*if (!$manager->pluginInstalled('NP_' . $pluginName))
            return;*/

        $plugin =& $manager->getPlugin('NP_' . $pluginName);
        if (!$plugin) {
            return;
        }
        if ($this->skintype == 'template') {
            if (!method_exists($plugin, 'doAdminTemplateVar')) {
                return;
            }
        } else {
            if (!method_exists($plugin, 'doAdminSkinVar')) {
                return;
            }
        }
        // get arguments
        $params = func_get_args();
        // remove plugin name
        array_shift($params);
        // add skin type on front
        array_unshift($params, $this->skintype);
        if ($this->skintype == 'template') {
            call_user_func_array(array(&$plugin, 'doAdminTemplateVar'), $params);
        } else {
            call_user_func_array(array(&$plugin, 'doAdminSkinVar'), $params);
        }
    }

    /**
     * Parse skinvar query
     * (includes the search query)
     */
    function parse_query() {
        global $query;
        echo ENTITY::hsc($query, ENT_QUOTES);
    }
    
    /**
     * Parse skinvar referer
     */
    function parse_referer() {
        echo ENTITY::hsc(serverVar('HTTP_REFERER'), ENT_QUOTES);
    }

    /**
     * Parse skinvar searchform
     */
    function parse_searchform($blogname = '', $templateName = '')
    {
        global $CONF, $manager, $maxresults;
        if ($blogname) {
            $blog =& $manager->getBlog(getBlogIDFromName($blogname));
        } else {
            global $blog;
        }
        // use default blog when no blog is selected
        $this->formdata = array(
            'id'    => $blog ? $blog->getID() : $CONF['DefaultBlog'],
            'query' => ENTITY::hsc(getVar('query'), ENT_QUOTES),
        );
        $this->doForm('searchform');
    }

    /**
     * Parse skinvar self
     */
    function parse_self() {
        global $CONF;
        echo $CONF['Self'];
    }

    /**
     * Parse skinvar sitevar
     * (include a sitevar)   
     */
    function parse_sitevar($which) {
        global $CONF;
        switch($which) {
            case 'url':
                echo $CONF['IndexURL'];
                break;
            case 'name':
                echo $CONF['SiteName'];
                break;
            case 'admin':
                echo $CONF['AdminEmail'];
                break;
            case 'adminurl':
                echo $CONF['AdminURL'];
        }
    }

    /**
     * Parse skinname
     */
    function parse_skinname() {
        echo $this->skin->getName();
    }
    
    /**
     * Parse skintype (experimental)
     */
    function parse_skintype() {
        echo $this->skintype;
    }

    /**
     * Parse text
     */
    function parse_text($which)
    {
        if (defined($which)) {
            echo constant($which);
        }
    }

    /**
     * Parse sprinttext
     */
    function parse_sprinttext($which, $val)
    {
        if (defined($which)) {
            $base = constant($which);
        } else {
            $base = $which;
        }
        if (preg_match('![^<|%].*[^%|>]!', $val, $matchies)) {
            if (preg_match('![(].*[^)]!', $matchies[0], $args)) {
               $arg = trim($args[0], '()');
                $met = 'parse_' . substr($matchies[0], 0, strpos($matchies[0], '('));
            } else {
                $met = 'parse_' . $matchies[0];
            }
            if (method_exists($this, $met)) {
                $value = call_user_func(array(&$this, $met), $arg);
            }
        }
        if (!isset($value) || empty($value)) {
            $value = $val;
        }
        echo sprintf($base, $value);
    }

    /**
     * Parse ticket
     */
    function parse_ticket()
    {
        global $manager;
        $manager->addTicketHidden();
    }

    /**
     * Parse skinvar version
     * (include nucleus versionnumber)   
     */
    function parse_version() {
        global $nucleus;
        echo 'Nucleus CMS ' . $nucleus['version'];
    }

    /**
     * Parse skinvar versioncheckurl
     */
    function parse_versioncheckurl()
    {
        echo sprintf(_ADMIN_SYSTEMOVERVIEW_VERSIONCHECK_URL, getNucleusVersion(), getNucleusPatchLevel());
    }

    /**
     * Parse skinvar newestcompare
     */
    function parse_newestcompare()
    {
        global $nucleus;
        $newestVersion  = getLatestVersion();
        $newestCompare  = str_replace('/', '.', $newestVersion);
        $currentVersion = str_replace(array('/', 'v'), array('.', ''), $nucleus['version']);
        if ($newestVersion && version_compare($newestCompare, $currentVersion, '>')) {
            echo '<br /><a style="color:red" href="http://nucleuscms.org/upgrade.php" title="' . _ADMIN_SYSTEMOVERVIEW_LATESTVERSION_TITLE . '">';
            echo _ADMIN_SYSTEMOVERVIEW_LATESTVERSION_TEXT . $newestVersion . '</a>';
        }
    }

    /**
     * Parse skinvar extrahead
     */
    function parse_extrahead()
    {
        global $manager;
        $extrahead = $this->objAdmin->extrahead;
        $manager->notify(
            'AdminPrePageHead',
            array(
                'extrahead' => &$extrahead,
                'action'    => $this->objAdmin->action
            )
        );
        echo $extrahead;
    }

    /**
     * Parse skinvar date
     */
    function parse_date($format = 'c')
    {
        global $CONF, $manager;
        echo formatDate($format, time(), 'iso8601', $manager->getBlog(intval($CONF['DefaultBlog'])));
    }

    /**
     * Parse skinvar qmanuaddselect
     */
    function parse_qmenuaddselect($templateName = '')
    {
        global $member;
        $showAll = requestVar('showall');
        if (($member->isAdmin()) && ($showAll == 'yes')) {
            // Super-Admins have access to all blogs! (no add item support though)
            $query =  'SELECT bnumber as value, bname as text'
                   . ' FROM ' . sql_table('blog')
                   . ' ORDER BY bname';
        } else {
            $query =  'SELECT bnumber as value, bname as text'
                   . ' FROM ' . sql_table('blog') . ', ' . sql_table('team')
                   . ' WHERE tblog=bnumber and tmember=' . $member->getID()
                   . ' ORDER BY bname';
        }
        $template['name']       = 'blogid';
        $template['tabindex']   = 15000;
        $template['extra']      = _QMENU_ADD_SELECT;
        $template['selected']   = -1;
        $template['shorten']    = 10;
        $template['shortenel']  = '';
        $template['javascript'] = 'onchange="return form.submit()"';
        skinableShowlist($query, 'select', $template, $templateName);
    }

    /**
     * Parse skinvar quickmenu
     */
    function parse_quickmenu($templateName = '')
    {
        global $manager;
        $templates = array();
        $template  = array();
        if (!empty($templateName)) {
            $templates = skinableTEMPLATE::read($templateName);
        }
        $pluginExtras = array();
        $manager->notify(
            'QuickMenu',
            array(
                'options' => &$pluginExtras
            )
        );
        if (count($pluginExtras) > 0) {
            if (isset($templates['PLUGIN_QUICKMENU_TITLE']) || !empty($templates['PLUGIN_QUICKMENU_TITLE'])) {
                $template['title'] = $templates['PLUGIN_QUICKMENU_TITLE'];
            } else {
                $template['title'] = '<h2><%text(_QMENU_PLUGINS)%></h2>';
            }
            $handler = new skinableACTIONS($this->skintype, $template, $this->objAdmin);
            $parser  = new PARSER(skinableACTIONS::getDefinedActions(), $handler);
            $parser->parse($template['title']);
            if (isset($templates['PLUGIN_QUICKMENU_HEAD']) || !empty($templates['PLUGIN_QUICKMENU_HEAD'])) {
                $template['head'] = $templates['PLUGIN_QUICKMENU_HEAD'];
            } else {
                $template['head'] = '<ul>';
            }
            echo $template['head'];
            if (isset($templates['PLUGIN_QUICKMENU_BODY']) || !empty($templates['PLUGIN_QUICKMENU_BODY'])) {
                $template['body'] = $templates['PLUGIN_QUICKMENU_BODY'];
            } else {
                $template['body'] = '<li><a href="<%plugadminurl%>" title="<%plugadmintooltip%>"><%plugadmintitle%></a></li>';
            }
            foreach ($pluginExtras as $aInfo) {
                $data = array(
                    'plugadminurl'     => ENTITY::hsc($aInfo['url'], ENT_QUOTES),
                    'plugadmintooltip' => ENTITY::hsc($aInfo['tooltip'], ENT_QUOTES),
                    'plugadmintitle'   => ENTITY::hsc($aInfo['title'], ENT_QUOTES),
                );
                echo TEMPLATE::fill($template['body'], $data);
            }
            if (isset($templates['PLUGIN_QUICKMENU_FOOT']) || !empty($templates['PLUGIN_QUICKMENU_FOOT'])) {
                $template['foot'] = $templates['PLUGIN_QUICKMENU_FOOT'];
            } else {
                $template['foot'] = '</ul>';
            }
            echo $template['foot'];
        }
    }

    /**
     * Parse skinvar passrequestvars
     */
    function parse_passrequestvars()
    {
        $oldaction = postVar('oldaction');
        if (($oldaction != 'logout')  && ($oldaction != 'login')  && $this->objAdmin->passvar) {
            if (!postVar('customaction')) {
                passRequestVars();
            }
        }
    }

    /**
     * Parse skinvar headmessage
     */
    function parse_headmessage()
    {
        if (!empty($this->objAdmin->headMess)) {
            echo '<p>' . _MESSAGE . ': ' . ENTITY::hsc($this->objAdmin->headMess, ENT_QUOTES) . "</p>\n";
        }
    }

    /**
     * Parse skinvar yrbloglist
     */
    function parse_yrbloglist($templateName = '')
    {
        global $member;
        $showAll = requestVar('showall');
        if (($member->isAdmin()) && ($showAll == 'yes')) {
            // Super-Admins have access to all blogs! (no add item support though)
            $query =  'SELECT bnumber, bname, 1 as tadmin, burl, bshortname'
                   . ' FROM ' . sql_table('blog')
                   . ' ORDER BY bnumber';
        } else {
            $query =  'SELECT bnumber, bname, tadmin, burl, bshortname'
                   . ' FROM ' . sql_table('blog') . ', ' . sql_table('team')
                   . ' WHERE tblog=bnumber and tmember=' . $member->getID()
                   . ' ORDER BY bnumber';
        }
        $template['content']    = 'bloglist';
        $template['superadmin'] = $member->isAdmin();
        $amount                 = skinableShowlist($query, 'table', $template, $templateName);
        if (($showAll != 'yes') && ($member->isAdmin())) {
            $total = quickQuery('SELECT COUNT(*) as result FROM ' . sql_table('blog'));
            if ($total > $amount)
                echo '<p><a href="index.php?action=overview&amp;showall=yes">' . _OVERVIEW_SHOWALL . '</a></p>';
        }
        if ($amount == 0) {
            echo _OVERVIEW_NOBLOGS;
        } elseif($amount != 0) {
            echo '<h2>' . _OVERVIEW_YRDRAFTS . '</h2>';
            $query =  'SELECT ititle, inumber, bshortname'
                   . ' FROM ' . sql_table('item'). ', ' . sql_table('blog')
                   . ' WHERE iauthor='.$member->getID().' and iblog=bnumber and idraft=1';
            $template['content'] = 'draftlist';
            $amountdrafts = skinableShowlist($query, 'table', $template, $templateName);
            if ($amountdrafts == 0) {
                echo _OVERVIEW_NODRAFTS;
            }
        }

    }

    /**
     * Parse skinvar adminbloglink
     */
    function parse_adminbloglink($templateName = '')
    {
        global $manager;
        $blogid    =  intRequestVar('blogid');
        $blog      =& $manager->getBlog($blogid);
        $templates = array();
        if (!empty($templateName)) {
            $templates = skinableTEMPLATE::read($templateName);
        }
        if (isset($templates['ADMIN_BLOGLINK']) || !empty($templates['ADMIN_BLOGLINK'])) {
            $template = $templates['ADMIN_BLOGLINK'];
        } else {
            $template = '<a href="<%url%>" title="<%adminbloglinktitle%>"><%blogname%></a>';
        }
        $data = array(
            'url'                => ENTITY::hsc($blog->getURL(), ENT_QUOTES),
            'adminbloglinktitle' => _BLOGLIST_TT_VISIT,
            'blogname'           => ENTITY::hsc($blog->getName(), ENT_QUOTES)
        );
        echo TEMPLATE::fill($template, $data);
    }

    /**
     * Parse skinvar ilistaddnew
     */
    function parse_ilistaddnew()
    {
        $blogid = intRequestVar('blogid');
        if (intPostVar('start') == 0) {
            echo '<p><a href="index.php?action=createitem&amp;blogid=' . $blogid . '">' . _ITEMLIST_ADDNEW . '</a></p>';
        }
    }

    /**
     * Parse skinvar itemnavlist
     */
    function parse_itemnavlist()
    {
        global $CONF, $manager, $member;
        if ($this->skintype == 'itemlist') {
            $blogid =  intRequestVar('blogid');
            $blog   =& $manager->getBlog($blogid);
        }
        if (postVar('start')) {
            $start = intPostVar('start');
        } else {
            $start = 0;
        }
        // amount of items to show
        if (postVar('amount')) {
            $amount = intPostVar('amount');
        } else {
            $amount = intval($CONF['DefaultListSize']);
            if ($amount < 1) {
                $amount = 10;
            }
        }
        $query  = 'SELECT '
                . '    bshortname, '
                . '    cname, '
                . '    mname, '
                . '    ititle, '
                . '    ibody, '
                . '    inumber, '
                . '    idraft, '
                . '    itime '
                . 'FROM '
                .      sql_table('item') . ', '
                .      sql_table('blog') . ', '
                .      sql_table('member') . ', '
                .      sql_table('category') . ' '
                . 'WHERE '
                . '    iblog   = bnumber '
                . 'and iauthor = mnumber '
                . 'and icat    = catid ';
        if ($this->skintype == 'itemlist') {
            $query          .= 'and iblog   = ' . $blogid;
            $template['now'] = $blog->getCorrectTime(time());
            // non-blog-admins can only edit/delete their own items
            if (!$member->blogAdminRights($blogid)) {
                $query .= ' and iauthor = ' . $member->getID();
            }
        } elseif ($this->skintype == 'browseownitems') {
            $query          .= 'and iauthor   = ' . $member->getID();
            $blogid          = 0;
            $template['now'] = time();
        }
        $search = postVar('search');    // search through items
        if (!empty($search)) {
            $query .= ' and ((ititle LIKE "%' . sql_real_escape_string($search) . '%") '
                    . '  or  (ibody LIKE "%' . sql_real_escape_string($search) . '%") '
                    . '  or  (imore LIKE "%' . sql_real_escape_string($search) . '%"))';
        }
        $query .= ' ORDER BY itime DESC'
                . " LIMIT $start,$amount";

        $template['content'] = 'itemlist';

//        NP_SkinableAdmin::loadSkinableClass('skinableENCAPSULATE');
        $navList = new skinableNAVLIST($this->skintype, $start, $amount, 0, 1000, $blogid, $search, 0);
        $navList->showBatchList('item', $query, 'table', $template);
    }

    /**
     * Parse skinvar commentnavlist
     */
    function parse_commentnavlist()
    {
        global $CONF, $manager, $member;
        // start index
        if (postVar('start')) {
            $start = intPostVar('start');
        } else {
            $start = 0;
        }
        // amount of items to show
        if (postVar('amount')) {
            $amount = intPostVar('amount');
        } else {
            $amount = intval($CONF['DefaultListSize']);
            if ($amount < 1) {
                $amount = 10;
            }
        }
        $query = 'SELECT '
               . '    cbody, '
               . '    cuser, '
               . '    cmail, '
               . '    cemail, '
               . '    mname, '
               . '    ctime, '
               . '    chost, '
               . '    cnumber, '
               . '    cip, '
               . '    citem '
               . 'FROM '
               .      sql_table('comment') . ' '
               . 'LEFT OUTER JOIN '
               .      sql_table('member') . ' '
               . 'ON '
               . '     mnumber = cmember '
               . 'WHERE ';
        if ($this->skintype == 'itemcommentlist') {
            $itemid                = intRequestVar('itemid');
            $query                .= ' citem = ' . $itemid;
            $template['canAddBan'] = $member->blogAdminRights(intRequestVar('blogid'));
            $bid                   = 0;
            $nonComments           = _NOCOMMENTS;
        } elseif ($this->skintype == 'browseowncomments') {
            $itemid                = 0;
            $query                .= ' cmember = ' . $member->getID();
            $template['canAddBan'] = 0;
            $bid                   = 0;
            $nonComments           = _NOCOMMENTS_YOUR;
        } elseif ($this->skintype == 'blogcommentlist') {
            $itemid                = 0;
            $query                .= ' cblog = ' . intRequestVar('blogid');
            $template['canAddBan'] = $member->blogAdminRights(intRequestVar('blogid'));
            $bid                   = intRequestVar('blogid');
            $nonComments           = _NOCOMMENTS_BLOG;
        }
        $search = postVar('search');
        if (!empty($search)) {
            $query .= ' and cbody LIKE "%' . sql_real_escape_string($search) . '%"';
        }

        $query .= ' ORDER BY ctime ASC'
                . " LIMIT $start,$amount";

        $template['content'] = 'commentlist';

//        NP_SkinableAdmin::loadSkinableClass('skinableENCAPSULATE');
        $navList = new skinableNAVLIST($this->skintype, $start, $amount, 0, 1000, $bid, $search, $itemid);
        $navList->showBatchList('comment', $query, 'table', $template, $nonComments);

    }

    /**
     * Parse skinvar adminbatchaction
     */
    function parse_adminbatchaction()
    {
//        var_dump($_REQUEST);
        echo ENTITY::hsc(requestVar('batchaction'), ENT_QUOTES);
    }

    /**
     * Parse skinvar adminbatchlist
     */
    function parse_adminbatchlist($templateName = '')
    {
        global $manager;
        $templates = array();
        if (!empty($templateName)) {
            $templates = skinableTEMPLATE::read($templateName);
        }
        if (isset($templates['ADMIN_BATCHLIST']) || !empty($templates['ADMIN_BATCHLIST'])) {
            $template = $templates['ADMIN_BATCHLIST'];
        }else {
            $template = '<li><%text(_BATCH_EXECUTING)%><b><%adminbatchaction%></b>'
                      . '<%batchlisttype%> <b><%batchid%></b>...'
                      . '<b><%batchlistmsg%></b></li>' . "\n";
        }

        $selected = requestIntArray('batch');
        $action   = requestVar('batchaction');

        switch ($this->skintype) {
            case 'batchitem':
                $batchlisttype = _BATCH_ONITEM;
                $deleteaction  = 'deleteOneItem';
                $moveaction    = 'moveOneItem';
                $destid        = intRequestVar('destcatid');
                break;
            case 'batchcomment':
                $batchlisttype = _BATCH_ONCOMMENT;
                $deleteaction  = 'deleteOneComment';
                break;
            case 'batchmember':
                $batchlisttype = _BATCH_ONMEMBER;
                $deleteaction  = 'deleteOneMember';
                $setadminsql   = sql_table('member') . ' SET madmin = 1 WHERE mnumber = ';
                $unsetchksql   = 'SELECT * FROM ' . sql_table('member') . ' WHERE madmin = 1 AND mcanlogin = 1';
                $unsetupsql    = sql_table('member') . ' SET madmin = 0 WHERE mnumber = ';
                $unseterrmsg   = _ERROR_ATLEASTONEADMIN;
                break;
            case 'batchteam':
                $blogid        = intRequestVar('blogid');
                $batchlisttype = _BATCH_ONTEAM;
                $deleteaction  = 'deleteOneTeamMember';
                $setadminsql   = sql_table('team') . ' SET tadmin = 1 WHERE tblog = ' . $blogid . ' AND tmember = ';
                $unsetchksql   = 'SELECT * FROM ' . sql_table('team') . ' WHERE tadmin = 1 AND tblog = ' . $blogid;
                $unseterrmsg   = _ERROR_ATLEASTONEBLOGADMIN;
                $unsetupsql    = sql_table('team') . ' SET tadmin = 0 WHERE tblog = ' . $blogid . ' AND tmember = ';
                break;
            case 'batchcategory':
                $batchlisttype = _BATCH_ONCATEGORY;
                $deleteaction  = 'deleteOneCategory';
                $moveaction    = 'moveOneCategory';
                $destid        = intRequestVar('destblogid');
                break;
        }
        // walk over all selectedids and perform action
        foreach ($selected as $selectedid) {
            $error      = '';
            $selectedid = intval($selectedid);
            switch($action) {
                case 'delete':
                    if ($this->skintype != 'batchteam') {
                        $error = $this->objAdmin->$deleteaction($selectedid);
                    } else {
                        $error  = $this->objAdmin->deleteOneTeamMember($blogid, $selectedid);
                   }
                    break;
                case 'move':
                    $error = $this->objAdmin->$moveaction($selectedid, $destid);
                    break;
                case 'setadmin':
                    // always succeeds
                    sql_query('UPDATE ' . $setadminsql . $selectedid);
                    $error = '';
                    break;
                case 'unsetadmin':
                    // there should always remain at least one super-admin
                    $r = sql_query($unsetchksql);
                    if (sql_num_rows($r) < 2) {
                        $error = $unseterrmsg;
                    } else {
                        sql_query('UPDATE ' . $unsetupsql . $selectedid);
                    }
                    break;
                default:
                    $error = _BATCH_UNKNOWN . ENTITY::hsc($action, ENT_QUOTES);
            }
            $data = array(
                'batchid'          => $selectedid,
                'batchlisttype'    => ENTITY::hsc($batchlisttype, ENT_QUOTES),
                'adminbatchaction' => ENTITY::hsc($action, ENT_QUOTES),
                'batchlistmsg'     => $error ? $error : _BATCH_SUCCESS,
            );
            $handler = new skinableACTIONS('template', $template, new ADMIN);
            $parser  = new skinablePARSER($handler);
            ob_start();
                $parser->parse($template);
                $template = ob_get_contents();
            ob_end_clean();
            echo TEMPLATE::fill($template, $data);
        }
    }

    /**
     * Parse skinvar requestblogid
     */
    function parse_requestblogid()
    {
        echo intRequestVar('blogid');
    }

    /**
     * Parse skinvar batchmovetitle
     */
    function parse_batchmovetitle()
    {
        $actionType = requestVar('action');
        switch ($actionType) {
            case 'batchitem':
                echo _MOVE_TITLE;
                break;
            case 'batchcategory':
                echo _MOVECAT_TITLE;
                break;
        }
    }

    /**
     * Parse skinvar batchmovebtn
     */
    function parse_batchmovebtn()
    {
        $actionType = requestVar('action');
        switch ($actionType) {
            case 'batchitem':
                echo _MOVE_BTN;
                break;
            case 'batchcategory':
                echo _MOVECAT_BTN;
                break;
        }
    }

    /**
     * Parse skinvar batchmovetype
     */
    function parse_batchmovetype()
    {
        echo ENTITY::hsc(requestVar('action'), ENT_QUOTES);
    }

    /**
     * Parse skinvar batchmovelist
     */
    function parse_batchmovelist()
    {
        $selected = requestIntArray('batch');
        foreach ($selected as $select) {
            echo '<input type="hidden" name="batch[' . ($select++) . ']" value="' . intval($select) . '" />';
        }
    }

    /**
     * Parse skinvar movedistselect
     */
    function parse_movedistselect()
    {
        $actionType = requestVar('action');
        switch ($actionType) {
            case 'batchitem':
                $this->objAdmin->selectBlogCategory('destcatid');
                break;
            case 'batchcategory':
                $this->objAdmin->selectBlog('destblogid');
                break;
            default:
                if ($this->skintype == 'itemmove') {
                    $query  = 'SELECT '
                            . '    icat as result '
                            . 'FROM '
                            .      sql_table('item') . ' '
                            . 'WHERE '
                            . '    inumber = %d';
                    $catid  = quickQuery(sprintf($query, intRequestVar('itemid')));
                   $this->objAdmin->selectBlogCategory('catid', $catid, 10, 1);
                }
                break;
        }
    }

    /**
     * Parse skinvar batchdeletetype
     */
    function parse_batchdeletetype()
    {
        echo ENTITY::hsc(requestVar('action'), ENT_QUOTES);
    }

    /**
     * Parse skinvar batchdeletelist
     */
    function parse_batchdeletelist()
    {
        $selected = requestIntArray('batch');
        $index    = 0;
        foreach ($selected as $select) {
            echo '<input type="hidden" name="batch[' . ($index++) . ']" value="' . intval($select) . '" />';
        }
        // add hidden vars for team & comment
        if (requestVar('action') == 'batchteam') {
            echo '<input type="hidden" name="blogid" value="' . intRequestVar('blogid') . '" />';
        }
        if (requestVar('action') == 'batchcomment') {
            echo '<input type="hidden" name="itemid" value="' . intRequestVar('itemid') . '" />';
        }
    }

    /**
     * Parse skinvar blogselectbox
     */
    function parse_blogselectbox()
    {
        global $member;
        $selectData = requestVar('selectData');
        $mode       = $selectData['mode'];
        $name       = ENTITY::hsc($selectData['name'], ENT_QUOTES);
        $tabindex   = ENTITY::hsc($selectData['tabindex'], ENT_QUOTES);
        $aBlogIds   = array_map('intval', $selectData['aBlogIds']);
        $showNewCat = intval($selectData['showNewCat']);
        $selected   = intval($selectData['selected']);
        echo '<select name="' . $name . '" tabindex="' . $tabindex . '">';

        // 1. select blogs (we'll create optiongroups)
        // (only select those blogs that have the user on the team)
        $queryBlogs = 'SELECT '
                    . '    bnumber, '
                    . '    bname '
                    . 'FROM '
                    .      sql_table('blog') . ' '
                    . 'WHERE '
                    . '    bnumber in (' . implode(',', $aBlogIds) . ') '
                    . 'ORDER BY '
                    . '    bname';
        $blogs      = sql_query($queryBlogs);
        if ($mode == 'category') {
            if (sql_num_rows($blogs) > 1) {
                $multipleBlogs = 1;
            }
            while ($oBlog = sql_fetch_object($blogs)) {
                if (isset($multipleBlogs) && !empty($multipleBlogs)) {
                    echo '<optgroup label="' . ENTITY::hsc($oBlog->bname, ENT_QUOTES) . '">';
                }

                // show selection to create new category when allowed/wanted
                if ($showNewCat) {
                    // check if allowed to do so
                    if ($member->blogAdminRights($oBlog->bnumber)) {
                        echo '<option value="newcat-' . $oBlog->bnumber . '">' . _ADD_NEWCAT . "</option>\n";
                    }
                }

                // 2. for each category in that blog
                $catQueriy  = 'SELECT '
                            . '    cname, '
                            . '    catid '
                            . 'FROM '
                            .      sql_table('category') . ' '
                            . 'WHERE '
                            . '    cblog = %d '
                            . 'ORDER BY '
                            . '    cname ASC';
                $categories = sql_query(sprintf($catQueriy, $oBlog->bnumber));
                while ($oCat = sql_fetch_object($categories)) {
                    if ($oCat->catid == $selected) {
                        $selectText = ' selected="selected" ';
                    } else {
                        $selectText = '';
                    }
                    echo '<option value="' . $oCat->catid . '" ' . $selectText . '>' . ENTITY::hsc($oCat->cname, ENT_QUOTES) . "</option>\n";
                }

                if (isset($multipleBlogs) && !empty($multipleBlogs)) {
                    echo '</optgroup>';
                }
            }
        } else {
            // blog mode
            while ($oBlog = sql_fetch_object($blogs)) {
                echo '<option value="' . $oBlog->bnumber . '"';
                if ($oBlog->bnumber == $selected) {
                    echo ' selected="selected"';
                }
                echo '>' . ENTITY::hsc($oBlog->bname, ENT_QUOTES) . '</option>';
            }
        }
        echo '</select>';
    }

    /**
     * Parse skinvar deleteitemid
     */
    function parse_deleteitemid()
    {
        echo intRequestVar('itemid');
    }

    /**
     * Parse skinvar deleteitemtitle
     */
    function parse_deleteitemtitle()
    {
        global $manager;
        $itemid = intRequestVar('itemid');
        $item  =& $manager->getItem($itemid, 1, 1);
        echo ENTITY::hsc(strip_tags($item['title']), ENT_QUOTES);
    }

    /**
     * Parse skinvar deleteitembody
     */
    function parse_deleteitembody()
    {
        global $manager;
        $itemid = intRequestVar('itemid');
        $item   =& $manager->getItem($itemid, 1, 1);
        $body   =  strip_tags($item['body']);
        echo ENTITY::hsc(shorten($body, 300, '...'), ENT_QUOTES);
    }

    /**
     * Parse skinvar moveitemid
     */
    function parse_moveitemid()
    {
        echo intRequestVar('itemid');
    }

    /**
     * Parse skinvar editcomment
     */
    function parse_editcomment($type = 'id')
    {
        global $manager;
        $commentid = intRequestVar('commentid');
        $comment   = COMMENT::getComment($commentid);
        $manager->notify('PrepareCommentForEdit', array('comment' => &$comment));
        switch ($type) {
            case 'id':
                echo intRequestVar('commentid');
                break;
            case 'user':
                if (isset($comment['member']) && !empty($comment['member'])) {
                    echo $comment['member'] . " (" . _EDITC_MEMBER . ")";
                } else {
                    echo $comment['user'] . " (" . _EDITC_NONMEMBER . ")";
                }
                break;
            case 'date':
                echo date("Y-m-d @ H:i", $comment['timestamp']);
                break;
            case 'body':
                $comment['body'] = str_replace('<br />', '', $comment['body']);
                $comment['body'] = eregi_replace("<a href=['\"]([^'\"]+)['\"]( rel=\"nofollow\")?>[^<]*</a>", "\\1", $comment['body']);
                echo $comment['body'];
            default:
                echo $comment[$type];
                break;
        }
    }

    /**
     * Parse skinvar deletecomment
     */
    function parse_deletecomment($type = 'id')
    {
        $commentid = intRequestVar('commentid');
        $comment   = COMMENT::getComment($commentid);
        switch ($type) {
            case 'id':
                echo intRequestVar('commentid');
                break;
            case 'author':
                if (isset($comment['member']) && !empty($comment['member'])) {
                    echo $comment['member'];
                } else {
                    echo $comment['user'];
                }
                break;
            case 'body':
                $body = strip_tags($comment['body']);
                echo ENTITY::hsc(shorten($body, 300, '...'), ENT_QUOTES);
        }
    }

    /**
     * Parse skinvar editmemberlist
     */
    function parse_editmemberlist($templateName = '')
    {
        global $manager;
        // show list of members with actions
        $query =  'SELECT *'
               . ' FROM '.sql_table('member');
        $template['content']  = 'memberlist';
        $template['tabindex'] = 10;

//        NP_SkinableAdmin::loadSkinableClass('skinableENCAPSULATE');
        $batch = new skinableBATCH('member');
        $batch->showlist($query, 'table', $template, _LISTS_NOMORE, $templateName);
    }

    /**
     * Parse skinvar helplink
     */
    function parse_helplink($topic = '')
    {
        if (empty($topic)) {
            return;
        }
        help($topic);
    }

    /**
     * Parse skinvar inputyesno
     */
    function parse_inputyesno($name, $checkedval, $tabindex = 0, $value1 = 1, $value2 = 0, $yesval = _YES, $noval = _NO, $isAdmin = 0, $templateName = '')
    {
        self::input_yesno($name, $checkedval, $tabindex, $value1, $value2, $yesval, $noval, $isAdmin, $templateName );
    }

    /**
     * Parse skinvar editmember
     */
    function parse_editmember($type = 'id', $templateName = '')
    {
        global $CONF, $manager, $member;
        $memberid = intRequestVar('memberid');
        $mem      = MEMBER::createFromID($memberid);
        switch ($type) {
            case 'id':
                echo intRequestVar('memberid');
                break;
            case 'displayname':
                if ($this->skintype == 'teamdelete' || $this->skintype == 'memberdelete') {
                    echo ENTITY::hsc($mem->getDisplayName(), ENT_QUOTES);
                } else {
                    $dispName = ENTITY::hsc($mem->getDisplayName(), ENT_QUOTES);
                    if ($CONF['AllowLoginEdit'] || $member->isAdmin()) {
                        echo '<input name="name" tabindex="10" maxlength="32" size="32" value="' . $dispName . '" />';
                    } else {
                        echo $dispName;
                    }
                }
                break;
            case 'realname':
                echo ENTITY::hsc($mem->getRealName(), ENT_QUOTES);
                break;
            case 'email':
                echo ENTITY::hsc($mem->getEmail(), ENT_QUOTES);
                break;
            case 'url':
                echo ENTITY::hsc($mem->getURL(), ENT_QUOTES);
                break;
            case 'admin':
                $this->parse_inputyesno('admin', $mem->isAdmin(), 60, 1, 0, _YES, _NO, 0, $templateName);
                break;
            case 'canlogin':
                $this->parse_inputyesno('canlogin', $mem->canLogin(), 70, 1, 0, _YES, _NO, $mem->isAdmin(), $templateName);
                break;
            case 'notes':
                echo ENTITY::hsc($mem->getNotes(), ENT_QUOTES);
                break;
            case 'autosave':
                $this->parse_inputyesno('autosave', $mem->getAutosave(), 87, 1, 0, _YES, _NO, 0, $templateName);
                break;
            default:
                break;
        }
    }

    /**
     * Parse skinvar languageselectoptions
     */
    function parse_languageselectoptions()
    {
        $locales = i18n::get_available_locale_list();
        $memid   = intRequestVar('memberid');
        if ($memid)
        {
            $mem = MEMBER::createFromID($memid);
            if ( !$mem->getLocale() || !in_array($mem->getLocale(), $locales) )
            {
                echo "<option value=\"\" selected=\"selected\">" . ENTITY::hsc(_MEMBERS_USESITELANG) . "</option>\n";
            }
            else
            {
                echo "<option value=\"\">" . ENTITY::hsc(_MEMBERS_USESITELANG) . "</option>\n";
            }
        }
        else
        {
            if ( !i18n::get_current_locale() || !in_array(i18n::get_current_locale(), $locales) )
            {
                echo "<option value=\"\" selected=\"selected\">en_Latn_US</option>\n";
            }
        }
        foreach ( $locales as $locale )
        {
            if ($memid)
            {
                if ( $locale == $mem->getLocale() )
                {
                    echo "<option value=\"{$locale}\" selected=\"selected\">{$locale}</option>\n";
                }
                else
                {
                    echo "<option value=\"{$locale}\">{$locale}</option>\n";
                }
            }
            else
            {
                if ( $locale == i18n::get_current_locale() )
                {
                    echo "<option value=\"{$locale}\" selected=\"selected\">{$locale}</option>\n";
                }
                else
                {
                    echo "<option value=\"{$locale}\">{$locale}</option>\n";
                }
            }
        }
/*        global $DIR_LANG, $CONF, $manager;
        $memid = intRequestVar('memberid');
        $files = scandir($DIR_LANG);
        foreach ($files as $file) {
            if (preg_match("/^(.*)\.php$/", $file, $matches)) {
                $name = $matches[1];
                $opts = '<option value="' . $matches[1] . '"';
                if ($memid) {
                    $mem = MEMBER::createFromID($memid);
                    if ($name == $mem->getLanguage()) {
                        $opts .= ' selected="selected"';
                    }
                } elseif ($name == $CONF['Language']) {
                    $opts .= ' selected="selected"';
                }
                $lang = _LANGUAGEFILES_ . strtoupper($name);
                $opts .= '>' . constant($lang) . "</option>\n";
                echo $opts;
            }
        }*/
    }

    /**
     * Parse skinvar adminstyleseets
     */
    function parse_adminstyleseets()
    {
        global $CONF;
        $includePrefix = $this->skin->includePrefix;
        if (strlen($includePrefix) > 0) {
            $styleURL = ENTITY::hsc($CONF['AdminURL']) . 'adminskins/' . $includePrefix . 'admin_' . $CONF['AdminCSS'] . '.css';
        } else {
            $styleURL = ENTITY::hsc($CONF['AdminURL']) . 'styles/admin_' . $CONF['AdminCSS'] . '.css';
        }
        echo $styleURL;
    }

    /**
     * Parse skinvar adminstyleselectoptions
     */
    function parse_adminstyleselectoptions()
    {
        global $CONF, $manager, $DIR_NUCLEUS;
        if (strlen($this->skin->includePrefix) > 0) {
        	$scndir = $DIR_NUCLEUS . 'adminskins/' . $this->skin->includePrefix;
        } else {
        	$scndir = $DIR_NUCLEUS . 'styles/';
        }
        $files = scandir($scndir);
        var_dump($files);

        foreach ($files as $file) {
            if (preg_match("/^admin_(.*)\.css$/", $file, $matches)) {
                $name = $matches[1];
                $opts = '<option value="' . $name . '"';
                if ($name == $CONF['AdminCSS']) {
                	$opts .= ' selected="selected"';
                }
                $opts .= '>' . $name . "</option>\n";
                echo $opts;
            }
        }
    }

    /**
     * Parse skinvar categorysetting
     */
    function parse_categorysetting($type)
    {
        $catid  = intRequestVar('catid');
        if ($type == 'id') {
            echo $catid;
            return;
        }
        $blogid = intRequestVar('blogid');
        $query  = 'SELECT '
                . '    * '
                . 'FROM '
                .      sql_table('category') . ' '
                . 'WHERE '
                . '    cblog = %d '
                . 'AND catid = %d';
        $res    = sql_query(sprintf($query, $blogid, $catid));
        $obj    = sql_fetch_object($res);
        switch ($type) {
            case 'name':
                echo ENTITY::hsc($obj->cname, ENT_QUOTES);
                break;
            case 'desc':
                echo ENTITY::hsc($obj->cdesc, ENT_QUOTES);
                break;
        }
    }

    /**
     * Parse skinvar pluginoptions
     */
    function parse_pluginoptions($type = 'global')
    {
        switch ($type) {
            case 'member':
                $id = intRequestVar('memberid');
                break;
            case 'blog':
                $id = intRequestVar('blogid');
                break;
            case 'category':
                $id = intRequestVar('catid');
                break;
        }
        $this->objAdmin->_insertPluginOptions($type, $id);
    }

    /**
     * Parse skinvar pluginextras
     */
    function parse_pluginextras($type = 'global')
    {
        global $manager;
        switch ($type) {
            case 'member':
                $id  = intRequestVar('memberid');
                $mem = MEMBER::createFromID($id);
                $manager->notify(
                    'MemberSettingsFormExtras',
                    array(
                        'member' => &$mem
                    )
                );
                break;
            case 'blog':
                $id  = intRequestVar('blogid');
                $blg = $manager->getBlog($id);
                $manager->notify(
                    'BlogSettingsFormExtras',
                    array(
                        'member' => &$blg
                    )
                );
                break;
            default:
                $manager->notify(
                    'GeneralSettingsFormExtras',
                    array(
                    )
                );
                break;
        }
    }

    /**
     * Parse skinvar activationmessage
     */
    function parse_activationmessage($type, $templateName = '')
    {
        global $CONF, $manager;
        $template = array();
        if (!empty($templateName)) {
            $template = skinableTEMPLATE::read($templateName);
        }
        $key = postVar('ackey');
        //$key = $this->objAdmin->sessionVar($CONF['CookiePrefix'] . 'ackey');
        if (!$key) {
            $this->objAdmin->error(_ERROR_ACTIVATE);
        }
        $info = MEMBER::getActivationInfo($key);
        if (!$info) {
            $this->objAdmin->error(_ERROR_ACTIVATE);
        }
        $mem  = MEMBER::createFromId($info->vmember);
        if (!$mem) {
            $this->objAdmin->error(_ERROR_ACTIVATE);
        }
        switch ($info->vtype) {
            case 'forgot':
                if (isset($template['ACTIVATE_FORGOT_TITLE']) && !empty($template['ACTIVATE_FORGOT_TITLE'])) {
                    $title = $template['ACTIVATE_FORGOT_TITLE'];
                } else {
                    $title = _ACTIVATE_FORGOT_TITLE;
                }
                if (isset($template['ACTIVATE_FORGOT_TEXT']) && !empty($template['ACTIVATE_FORGOT_TEXT'])) {
                    $text = $template['ACTIVATE_FORGOT_TEXT'];
                } else {
                    $text = _ACTIVATE_FORGOT_TEXT;
                }
                break;
            case 'register':
                if (isset($template['ACTIVATE_REGISTER_TITLE']) && !empty($template['ACTIVATE_REGISTER_TITLE'])) {
                    $title = $template['ACTIVATE_REGISTER_TITLE'];
                } else {
                    $title = _ACTIVATE_REGISTER_TITLE;
                }
                if (isset($template['ACTIVATE_REGISTER_TEXT']) && !empty($template['ACTIVATE_REGISTER_TEXT'])) {
                    $text = $template['ACTIVATE_REGISTER_TEXT'];
                } else {
                    $text = _ACTIVATE_REGISTER_TEXT;
                }
                break;
            case 'addresschange':
                if (isset($template['ACTIVATE_CHANGE_TITLE']) && !empty($template['ACTIVATE_CHANGE_TITLE'])) {
                    $title = $template['ACTIVATE_CHANGE_TITLE'];
                } else {
                    $title = _ACTIVATE_CHANGE_TITLE;
                }
                if (isset($template['ACTIVATE_CHANGE_TEXT']) && !empty($template['ACTIVATE_CHANGE_TEXT'])) {
                    $text = $template['ACTIVATE_CHANGE_TEXT'];
                } else {
                    $text = _ACTIVATE_CHANGE_TEXT;
                }
                break;
        }
        $aVars = array(
            'memberName' => ENTITY::hsc($mem->getDisplayName(), ENT_QUOTES),
            'realName'   => ENTITY::hsc($mem->getRealName(), ENT_QUOTES),
        );
        switch ($type) {
            case 'title':
                echo TEMPLATE::fill($title, $aVars);
                break;
            case 'text':
                echo TEMPLATE::fill($text,  $aVars);
                break;
            case 'ackey':
                echo ENTITY::hsc($key, ENT_QUOTES);
                break;
        }
    }

    /**
     * Parse skinvar adminerrormesg
     */
    function parse_adminerrormesg()
    {
        global $CONF;
        $message = '';
        if (requestVar('errormessage')) {
            $message = requestVar('errormessage');
        } elseif (cookieVar($CONF['CookiePrefix'] . 'errormessage')) {
            $message = cookieVar($CONF['CookiePrefix'] . 'errormessage');
        } elseif ($this->objAdmin->sessionVar($CONF['CookiePrefix'] . 'errormessage')) {
            $message = $this->objAdmin->sessionVar($CONF['CookiePrefix'] . 'errormessage');
        }
        echo ENTITY::hsc($message, ENT_QUOTES);
    }

    /**
     * Parse skinvar eventformextra
     */
    function parse_eventformextra($type = 'activation')
    {
        global $manager;
        switch ($type) {
            case 'activation':
                $key = requestVar('ackey');
                if (!$key) {
                    $this->objAdmin->error(_ERROR_ACTIVATE);
                }
                $info = MEMBER::getActivationInfo($key);
                if (!$info) {
                    $this->objAdmin->error(_ERROR_ACTIVATE);
                }
                $mem  = MEMBER::createFromId($info->vmember);
                if (!$mem) {
                    $this->objAdmin->error(_ERROR_ACTIVATE);
                }
                $data = array(
                    'type'   => 'activation',
                    'member' => $mem
                );
                break;
            case 'membermailform-notloggedin':
                $data = array(
                    'type' => 'membermailform-notloggedin',
                );
                break;
        }
        $manager->notify(
            'FormExtra',
            $data
        );
    }

    /**
     * Parse skinvar blogteamlist
     */
    function parse_blogteamlist($templateName = '')
    {
        global $manager;
        $blogid = intRequestVar('blogid');
        $query  = 'SELECT '
                . '    tblog, '
                . '    tmember, '
                . '    mname, '
                . '    mrealname, '
                . '    memail, '
                . '    tadmin '
                . 'FROM '
                .      sql_table('member') . ', '
                .      sql_table('team') . ' '
                . 'WHERE '
                . '    tmember = mnumber '
                . 'and tblog   = ' . $blogid;

        $template['content']  = 'teamlist';
        $template['tabindex'] = 10;

//        NP_SkinableAdmin::loadSkinableClass('skinableENCAPSULATE');
        $batch = new skinableBATCH('team');
        $batch->showlist($query, 'table', $template, _LISTS_NOMORE, $templateName);
    }

    /**
     * Parse skinvar newmemberselect
     */
    function parse_newmemberselect($templateName = '')
    {
        $blogid = intRequestVar('blogid');
        $query  = 'SELECT '
                . '    tmember '
                . 'FROM '
                .      sql_table('team') . ' '
                . 'WHERE '
                . '    tblog = ' . $blogid;
        $res    = sql_query($query);
        $tmem   = array();
        while($tmember = sql_fetch_object($res)) {
            $tmem[] = intval($tmember->tmember);
        }
        $query  = 'SELECT '
                . '    mname   as text, '
                . '    mnumber as value '
                . 'FROM '
                .      sql_table('member') . ' '
                . 'WHERE '
                . '    mnumber NOT IN (' . implode(', ', $tmem) . ')';
        $template['name']     = 'memberid';
        $template['tabindex'] = 10000;
        skinableShowlist($query, 'select', $template, $templateName);
    }

    /**
     * Parse skinvar blogteammembers
     */
    function parse_blogteammembers()
    {
        $blogid = intRequestVar('blogid');
        $query  = 'SELECT '
                . '    mname, '
                . '    mrealname '
                . 'FROM '
                .      sql_table('member') . ', '
                .      sql_table('team') . ' '
                . 'WHERE '
                . '    mnumber = tmember '
                . 'AND tblog   = %d';
        $res    = sql_query(sprintf($query, $blogid));
        $memberNames = array();
        while ($o = sql_fetch_object($res)) {
            $memberNames[] = ENTITY::hsc($o->mname) . ' (' . ENTITY::hsc($o->mrealname). ')';
        }
        echo implode(',', $memberNames);
    }

    /**
     * Parse skinvar defskinselect
     */
    function parse_defskinselect($type = 'blog', $templateName = '')
    {
        global $manager;
        $query  = 'SELECT '
                . '    sdname   as text, '
                . '    sdnumber as value '
                . 'FROM '
                .      sql_table('skin_desc');
        $blogid = intRequestVar('blogid');
        if ($blogid) {
            $blog                 = $manager->getBlog($blogid);
            $template['selected'] = $blog->getDefaultSkin();
        } else {
            global $CONF;
            $template['selected'] = $CONF['BaseSkin'];
        }
        if ($type == 'blog') {
            $nname = 'defskin';
        } else {
            $nname = 'BaseSkin';
        }
        $template['name']     = $nname;
        $template['tabindex'] = 50;
        skinableShowlist($query, 'select', $template, $templateName);
    }

    /**
     * Parse skinvar defcatselect
     */
    function parse_defcatselect($templateName = '')
    {
        global $manager;
        $blogid = intRequestVar('blogid');
        $blog   = $manager->getBlog($blogid);
        $query  = 'SELECT '
                . '    cname as text, '
                . '    catid as value '
                . 'FROM '
                .      sql_table('category') . ' '
                . ' WHERE '
                . '    cblog = ' . $blog->getID();
        $template['name']     = 'defcat';
        $template['selected'] = $blog->getDefaultCategory();
        $template['tabindex'] = 110;
        skinableShowlist($query, 'select', $template, $templateName);
    }

    /**
     * Parse skinvar adminskinselectoptions
     */
    function parse_adminskinselectoptions()
    {
        global $CONF;
        $query  = 'SELECT '
                . '    sdname as text, '
                . '    sdnumber as value '
                . 'FROM '
                .      sql_table('adminskin_desc');
        $template['name']     = 'adminskin';
        $template['selected'] = $CONF['DefaultAdminSkin'];
        $template['tabindex'] = 110;
        skinableShowlist($query, 'select', $template, '');
    }

    /**
     * Parse skinvar blogsettingyesno
     */
    function parse_blogsettingyesno($type, $templateName = '')
    {
        global $manager;
        $blogid = intRequestVar('blogid');
        $blog   = $manager->getBlog($blogid);
        switch ($type) {
            case 'convertbreaks':
                $checkedval = $blog->convertBreaks();
                $tabindex   = 55;
                break;
            case 'allowpastposting':
                $checkedval = $blog->allowPastPosting();
                $tabindex   = 57;
                break;
            case 'comments':
                $checkedval = $blog->commentsEnabled();
                $tabindex   = 60;
                break;
            case 'public':
                $checkedval = $blog->isPublic();
                $tabindex   = 70;
                break;
            case 'reqemail':
                $checkedval = $blog->emailRequired();
                $tabindex   = 72;
                break;
            case 'searchable':
                $checkedval = $blog->getSearchable();
                $tabindex   = 122;
                break;
        }
        $this->parse_inputyesno($type, $checkedval, $tabindex, 1, 0, _YES, _NO, 0, $templateName);
    }

    /**
     * Parse skinvar blognotifysetting
     */
    function parse_blognotifysetting($type)
    {
        global $manager;
        $blogid = intRequestVar('blogid');
        $blog   = $manager->getBlog($blogid);
        switch ($type) {
            case 'comment':
                if (!$blog->notifyOnComment()) {
                    return;
                }
                break;
            case 'vote':
                if (!$blog->notifyOnVote()) {
                    return;
                }
                break;
            case 'newitem':
                if (!$blog->notifyOnNewItem()) {
                    return;
                }
                break;
        }
        echo ' checked="checked"';
    }

    /**
     * Parse skinvar blogtime
     */
    function parse_blogtime($type, $format = '%H:%M', $offset = 0)
    {
        switch ($type) {
            case 'servertime':
                echo strftime($format, time() + $offset);
                break;
            case 'blogtime':
                global $manager;
                $bid = intRequestVar('blogid');
                $b   = $manager->getBlog($bid);
                echo strftime($format, $b->getCorrectTime() + $offset);
                break;
        }
    }

    /**
     * Parse skinvar blogcatlist
     */
    function parse_blogcatlist()
    {
        global $manager;
        $blogid = intRequestVar('blogid');
        $query  = 'SELECT '
                . '    * '
                . 'FROM '
                .      sql_table('category') . ' '
                . 'WHERE '
                . '    cblog = ' . $blogid
                . ' ORDER BY cname';

        $template['content']  = 'categorylist';
        $template['tabindex'] = 200;

//        NP_SkinableAdmin::loadSkinableClass('skinableENCAPSULATE');
        $batch = new skinableBATCH('member');
        $batch->showlist($query, 'table', $template);
    }

    /**
     * Parse skinvar editdesturl
     */
    function parse_editdesturl()
    {
        if (requestVar('desturl')) {
            echo ENTITY::hsc(requestVar('desturl'), ENT_QUOTES);
        }
    }

    /**
     * Parse skinvar selectlocalskinfiles
     */
    function parse_selectlocalskinfiles()
    {
        global $DIR_SKINS;
        $candidates = SKINIMPORT::searchForCandidates($DIR_SKINS);
        foreach ($candidates as $skinname => $skinfile) {
            $html = ENTITY::hsc($skinfile);
            echo '<option value="' . $html . '">' . $skinname . '</option>';
        }
    }

    /**
     * Parse skinvar selectlocaladminskinfiles
     */
    function parse_selectlocaladminskinfiles()
    {
        global $DIR_ADMINSKINS, $manager;
        $candidates = skinableSKINIMPORT::searchForCandidates($DIR_ADMINSKINS);
        foreach ($candidates as $skinname => $skinfile) {
            $html = ENTITY::hsc($skinfile);
            echo '<option value="' . $html . '">' . $skinname . '</option>';
        }
    }

    /**
     * Parse skinvar skinielist
     */
    function parse_skinielist($type, $templateName = '')
    {
        $templates = array();
        if ($templateName) {
            $templates = skinableTEMPLATE::read($templateName);
        }
        if (isset($templates['SKINIE_EXPORT_LIST']) && !empty($templates['SKINIE_EXPORT_LIST'])) {
            $template = $templates['SKINIE_EXPORT_LIST'];
        } else {
            $template = '<td><input type="checkbox" name="<%typeid%>"  id="<%expid%>" /><label for="<%expid%>"><%expname%></label></td>' . "\n"
                      . "<td><%expdesc%></td>\n"
                      . "</tr><tr>\n";
        }
        switch ($type) {
            case 'skin':
                $res = sql_query('SELECT * FROM ' . sql_table('skin_desc'));
                while ($skinObj = sql_fetch_object($res)) {
                    $data = array(
                        'typeid'  => 'skin[' . $skinObj->sdnumber . ']',
                        'expid'   => 'skinexp' . $skinObj->sdnumber,
                        'expname' => ENTITY::hsc($skinObj->sdname, ENT_QUOTES),
                        'expdesc' => ENTITY::hsc($skinObj->sddesc, ENT_QUOTES),
                    );
                    echo TEMPLATE::fill($template, $data);
                }
                break;
            case 'template':
                $res = sql_query('SELECT * FROM '.sql_table('template_desc'));
                while ($templateObj = sql_fetch_object($res)) {
                    $data = array(
                        'typeid'  => 'template[' . $templateObj->tdnumber . ']',
                        'expid'   => 'templateexp' . $templateObj->tdnumber,
                        'expname' => ENTITY::hsc($templateObj->tdname, ENT_QUOTES),
                        'expdesc' => ENTITY::hsc($templateObj->tddesc, ENT_QUOTES),
                    );
                    echo TEMPLATE::fill($template, $data);
                }
                break;
        }
    }

    /**
     * Parse skinvar adminskinielist
     */
    function parse_adminskinielist($type, $templateName = '')
    {
        $templates = array();
        if ($templateName) {
            $templates = skinableTEMPLATE::read($templateName);
        }
        if (isset($templates['SKINIE_EXPORT_LIST']) && !empty($templates['SKINIE_EXPORT_LIST'])) {
            $template = $templates['SKINIE_EXPORT_LIST'];
        } else {
            $template = '<td><input type="checkbox" name="<%typeid%>"  id="<%expid%>" /><label for="<%expid%>"><%expname%></label></td>' . "\n"
                      . "<td><%expdesc%></td>\n"
                      . "</tr><tr>\n";
        }
        switch ($type) {
            case 'skin':
                $res = sql_query('SELECT * FROM ' . sql_table('adminskin_desc'));
                while ($skinObj = sql_fetch_object($res)) {
                    $data = array(
                        'typeid'  => 'skin[' . $skinObj->sdnumber . ']',
                        'expid'   => 'skinexp' . $skinObj->sdnumber,
                        'expname' => ENTITY::hsc($skinObj->sdname, ENT_QUOTES),
                        'expdesc' => ENTITY::hsc($skinObj->sddesc, ENT_QUOTES),
                    );
                    echo TEMPLATE::fill($template, $data);
                }
                break;
            case 'template':
                $res = sql_query('SELECT * FROM '.sql_table('admintemplate_desc'));
                while ($templateObj = sql_fetch_object($res)) {
                    $data = array(
                        'typeid'  => 'template[' . $templateObj->tdnumber . ']',
                        'expid'   => 'templateexp' . $templateObj->tdnumber,
                        'expname' => ENTITY::hsc($templateObj->tdname, ENT_QUOTES),
                        'expdesc' => ENTITY::hsc($templateObj->tddesc, ENT_QUOTES),
                    );
                    echo TEMPLATE::fill($template, $data);
                }
                break;
        }
    }

    /**
     * Parse skinvar importskininfo
     */
    function parse_importskininfo($type)
    {
        switch ($type) {
            case 'info':
                echo ENTITY::hsc(requestVar('skininfo'), ENT_QUOTES);
                break;
            case 'snames':
                $dataArr = requestArray('skinnames');
                echo implode(' <em>' . _AND . '</em> ', $dataArr);
                break;
            case 'tnames':
                $dataArr = requestArray('tpltnames');
                echo implode(' <em>' . _AND . '</em> ', $dataArr);
                break;
            case 'sclashes':
                $dataArr = requestArray('skinclashes');
                echo implode(' <em>' . _AND . '</em> ', $dataArr);
                break;
            case 'tclashes':
                $dataArr = requestArray('tpltclashes');
                echo implode(' <em>' . _AND . '</em> ', $dataArr);
                break;
            case 'skinfile':
                echo ENTITY::hsc(requestVar('skinfile'), ENT_QUOTES);
                break;
            case 'mode':
                echo ENTITY::hsc(requestVar('mode'), ENT_QUOTES);
                break;
        }
    }

    /**
     * Parse skinvar templateoverview
     */
    function parse_templateoverview($templateName = '')
    {
        $query  = 'SELECT '
                . '    * '
                . 'FROM '
                .      sql_table('template_desc') . ' '
                . ' ORDER BY tdname';
        $template['content']  = 'templatelist';
        $template['tabindex'] = 10;
        skinableShowlist($query, 'table', $template, $templateName);
    }

    /**
     * Parse skinvar admintemplateoverview
     */
    function parse_admintemplateoverview($templateName = '')
    {
        $query  = 'SELECT '
                . '    * '
                . 'FROM '
                .      sql_table('admintemplate_desc') . ' '
                . ' ORDER BY tdname';
        $template['content']  = 'admintemplatelist';
        $template['tabindex'] = 10;
        skinableShowlist($query, 'table', $template, $templateName);
    }

    /**
     * Parse skinvar edittemplateinfo
     */
    function parse_edittemplateinfo($type, $description = '', $name = '', $help = '', $tabindex = 0, $big = 0, $tplt = '')
    {
        global $manager;
        $templateid          =  intRequestVar('templateid');
        $templatename        =  TEMPLATE::getNameFromId($templateid);
        $templatedescription =  TEMPLATE::getDesc($templateid);
        $template            =& $manager->getTemplate($templatename);
        switch ($type) {
            case 'id':
                echo intval($templateid);
                break;
            case 'name':
                echo ENTITY::hsc($templatename, ENT_QUOTES);
                break;
            case 'desc':
                echo ENTITY::hsc($templatedescription, ENT_QUOTES);
                break;
            case 'extratemplate':
                $tabidx       = 600;
                $pluginfields = array();
                $manager->notify(
                    'TemplateExtraFields',
                    array(
                        'fields' => &$pluginfields
                    )
                );
                $tmplt = array();
                if ($description) {
                    $tmplt = skinableTEMPLATE::read($description);
                }
                if (isset($tmplt['TEMPLATE_EDIT_EXPLUGNAME']) && !empty($tmplt['TEMPLATE_EDIT_EXPLUGNAME'])) {
                    $base = $tmplt['TEMPLATE_EDIT_EXPLUGNAME'];
                } else  {
                    $base = "</tr><tr>\n"
                          . "\t" . '<th colspan="2"><%explugtplname%>' . "</th>\n";
                }
                foreach ($pluginfields as $pfkey => $pfvalue) {
                    $data = array(
                        'explugtplname' => ENTITY::hsc($pfkey, ENT_QUOTES)
                    );
                    echo TEMPLATE::fill($base, $data);
                    foreach ($pfvalue as $pffield => $pfdesc) {
                        $this->_templateEditRow($template, $pfdesc, $pffield, '', ++$tabidx, 0, $name);
                    }
                }
                break;
            default:
                $desc = defined($description) ? constant($description) : $description;
                $name = defined($name) ? constant($name) : $name;
                $this->_templateEditRow($template, $desc, $name, $help, $tabindex, $big, $tplt);
                break;
        }
    }

    /**
     * Parse skinvar editadmintemplateinfo
     */
    function parse_editadmintemplateinfo($type, $description = '', $name = '', $help = '', $tabindex = 0, $big = 0, $tplt = '')
    {
        global $manager;
        $templateid          =  intRequestVar('templateid');
        $templatename        =  skinableTEMPLATE::getNameFromId($templateid);
        $templatedescription =  skinableTEMPLATE::getDesc($templateid);
        $template            =& skinableTEMPLATE::read($templatename);
        switch ($type) {
            case 'id':
                echo intval($templateid);
                break;
            case 'name':
                echo ENTITY::hsc($templatename, ENT_QUOTES);
                break;
            case 'desc':
                echo ENTITY::hsc($templatedescription, ENT_QUOTES);
                break;
            case 'extratemplate':
                $tabidx       = 600;
                $pluginfields = array();
                $manager->notify(
                    'AdminTemplateExtraFields',
                    array(
                        'fields' => &$pluginfields
                    )
                );
                $tmplt = array();
                if ($description) {
                    $tmplt = skinableTEMPLATE::read($description);
                }
                if (isset($tmplt['TEMPLATE_EDIT_EXPLUGNAME']) && !empty($tmplt['TEMPLATE_EDIT_EXPLUGNAME'])) {
                    $base = $tmplt['TEMPLATE_EDIT_EXPLUGNAME'];
                } else {
                    $base = "</tr><tr>\n"
                          . "\t" . '<th colspan="2"><%explugtplname%>' . "</th>\n";
                }
                foreach ($pluginfields as $pfkey => $pfvalue) {
                    $data = array(
                        'explugtplname' => ENTITY::hsc($pfkey, ENT_QUOTES)
                    );
                    echo TEMPLATE::fill($base, $data);
                    foreach ($pfvalue as $pffield => $pfdesc) {
                        $this->_templateEditRow($template, $pfdesc, $pffield, '', ++$tabidx, 0, $name);
                    }
                }
                break;
            default:
                $desc = defined($description) ? constant($description) : $description;
                $name = defined($name) ? constant($name) : $name;
                $this->_templateEditRow($template, $desc, $name, $help, $tabindex, $big, $tplt);
                break;
        }
    }

    /**
     * Template edit box
     */
    function _templateEditRow(&$template, $desc, $name, $help = '', $tabindex = 0, $big = 0, $tplt = '')
    {
        static $count = 1;
        if (!isset($template[$name])) {
            $template[$name] = '';
        }
        $tmplt = array();
        $base  = array();
        if ($tplt) {
            $tmplt = skinableTEMPLATE::read($tplt);
        }
        $data = array(
            'description'  => $desc,
            'help'         => empty($help) ? '' : helpHtml('template' . $help),
            'count'        => $count,
            'name'         => $name,
            'tabindex'     => $tabindex,
            'rows'         => $big ? 10 : 5,
        );
        if (isset($tmplt['TEMPLATE_EDIT_ROW_HEAD']) && !empty($tmplt['TEMPLATE_EDIT_ROW_HEAD'])) {
            $base['head'] = $tmplt['TEMPLATE_EDIT_ROW_HEAD'];
        } else {
            $base['head'] = "</tr><tr>\n"
                          . "\t<td>\n"
                          . "\t\t<%description%><%help%>\n"
                          . "\t</td>\n"
                          . "\t" . '<td id="td<%count%>">' . "\n"
                          . "\t\t" . '<textarea class="templateedit" name="<%name%>" tabindex="<%tabindex%>" cols="50" rows="<%rows%>" id="textarea<%count%>">';
        }
        echo TEMPLATE::fill($base['head'], $data);
        echo ENTITY::hsc($template[$name], ENT_QUOTES);
        if (isset($tmplt['TEMPLATE_EDIT_ROW_TAIL']) && !empty($tmplt['TEMPLATE_EDIT_ROW_TAIL'])) {
            $base['tail'] = $tmplt['TEMPLATE_EDIT_ROW_TAIL'];
        } else {
            $base['tail'] = "</textarea>\n\t</td>\n";
        }
        echo TEMPLATE::fill($base['tail'], $data);
        $count++;
    }

    /**
     * Parse skinvar skinoverview
     */
    function parse_skinoverview($templateName = '')
    {
        $query  = 'SELECT '
                . '    * '
                . 'FROM '
                .      sql_table('skin_desc') . ' '
                . ' ORDER BY sdname';
        $template['content']  = 'skinlist';
        $template['tabindex'] = 10;
        skinableShowlist($query, 'table', $template, $templateName);
    }

    /**
     * Parse skinvar adminskinoverview
     */
    function parse_adminskinoverview($templateName = '')
    {
        $query  = 'SELECT '
                . '    * '
                . 'FROM '
                .      sql_table('adminskin_desc') . ' '
                . ' ORDER BY sdname';
        $template['content']  = 'adminskinlist';
        $template['tabindex'] = 10;
        skinableShowlist($query, 'table', $template, $templateName);
    }

    /**
     * Parse skinvar editskin
     */
    function parse_editskin($type = 'id')
    {
        $skinid = intRequestVar('skinid');
        $skin   = new SKIN($skinid);
        switch ($type) {
            case 'id':
                echo intRequestVar('skinid');
                break;
            case 'name':
                echo ENTITY::hsc($skin->getName(), ENT_QUOTES);
                break;
            case 'desc':
                echo ENTITY::hsc($skin->getDescription(), ENT_QUOTES);
                break;
            case 'type':
                echo ENTITY::hsc($skin->getContentType(), ENT_QUOTES);
                break;
            case 'prefix':
                echo ENTITY::hsc($skin->getIncludePrefix(), ENT_QUOTES);
                break;
            case 'mode':
                $this->parse_inputyesno('inc_mode', $skin->getIncludeMode(), 120, 'skindir', 'normal', _PARSER_INCMODE_SKINDIR, _PARSER_INCMODE_NORMAL);
            default:
                break;
        }
    }

    /**
     * Parse skinvar editadminskin
     */
    function parse_editadminskin($type = 'id')
    {
        $skinid = intRequestVar('skinid');
        $skin   = new skinableSKIN($skinid);
        switch ($type) {
            case 'id':
                echo intRequestVar('skinid');
                break;
            case 'name':
                echo ENTITY::hsc($skin->getName(), ENT_QUOTES);
                break;
            case 'desc':
                echo ENTITY::hsc($skin->getDescription(), ENT_QUOTES);
                break;
            case 'type':
                echo ENTITY::hsc($skin->getContentType(), ENT_QUOTES);
                break;
            case 'prefix':
                echo ENTITY::hsc($skin->getIncludePrefix(), ENT_QUOTES);
                break;
            case 'mode':
                $this->parse_inputyesno('inc_mode', $skin->getIncludeMode(), 120, 'skindir', 'normal', _PARSER_INCMODE_SKINDIR, _PARSER_INCMODE_NORMAL);
            default:
                break;
        }
    }

    /**
     * Parse skinvar editskintype
     */
    function parse_editskintype($type = 'id')
    {
        global $CONF, $manager, $member;
        $skinid = intRequestVar('skinid');
        $skin   = new SKIN($skinid);
        $fNames = SKIN::getFriendlyNames();
        $sType  = strtolower(trim(requestVar('type')));
        switch ($type) {
            case 'id':
                echo intRequestVar('skinid');
                break;
            case 'name':
                echo ENTITY::hsc($skin->getName(), ENT_QUOTES);
                break;
            case 'desc':
                echo ENTITY::hsc($skin->getDescription(), ENT_QUOTES);
                break;
            case 'type':
                echo ENTITY::hsc($skin->getContentType(), ENT_QUOTES);
                break;
            case 'content':
                echo ENTITY::hsc($skin->getContent($sType), ENT_QUOTES);
                break;
            case 'skintype':
                $skinType = isset($fNames[$sType]) ? $fNames[$sType] : ucfirst($sType);
                echo ENTITY::hsc($skinType, ENT_QUOTES);
                break;
            case 'skintyperaw':
                echo ENTITY::hsc($sType, ENT_QUOTES);
                break;
            case 'prefix':
                echo ENTITY::hsc($skin->getIncludePrefix(), ENT_QUOTES);
                break;
            case 'mode':
                $incMode = $skin->getIncludeMode() ? _PARSER_INCMODE_SKINDIR : _PARSER_INCMODE_NORMAL;
                echo ENTITY::hsc($incMode, ENT_QUOTES);
                break;
            default:
                break;
        }
    }

    /**
     * Parse skinvar editadminskintype
     */
    function parse_editadminskintype($type = 'id')
    {
        global $CONF, $manager, $member;
        $skinid = intRequestVar('skinid');
        $skin   = new skinableSKIN($skinid);
        $fNames = skinableSKIN::getFriendlyNames();
        $sType  = strtolower(trim(requestVar('type')));
//        var_dump($skin);
        switch ($type) {
            case 'id':
                echo intRequestVar('skinid');
                break;
            case 'name':
                echo ENTITY::hsc($skin->getName(), ENT_QUOTES);
                break;
            case 'desc':
                echo ENTITY::hsc($skin->getDescription(), ENT_QUOTES);
                break;
            case 'type':
                echo ENTITY::hsc($skin->getContentType(), ENT_QUOTES);
                break;
            case 'content':
                echo ENTITY::hsc($skin->getContent($sType), ENT_QUOTES);
                break;
            case 'skintype':
                $skinType = isset($fNames[$sType]) ? $fNames[$sType] : ucfirst($sType);
                echo ENTITY::hsc($skinType, ENT_QUOTES);
                break;
            case 'skintyperaw':
                echo ENTITY::hsc($sType, ENT_QUOTES);
                break;
            case 'prefix':
                echo ENTITY::hsc($skin->getIncludePrefix(), ENT_QUOTES);
                break;
            case 'mode':
                $incMode = $skin->getIncludeMode() ? _PARSER_INCMODE_SKINDIR : _PARSER_INCMODE_NORMAL;
                echo ENTITY::hsc($incMode, ENT_QUOTES);
                break;
            default:
                break;
        }
    }

    /**
     * Check editing skintypehelp
     */
    function parse_skintypehelp()
    {
        $nowSkinType = strtolower(trim(requestVar('type')));
        $regularType = array(
            'index',
            'item',
            'archivelist',
            'archive',
            'search',
            'error',
            'member',
            'imagepopup'
        );
        if (in_array($nowSkinType, $regularType)) {
            help('skinpart' . $nowSkinType);
        } else {
            help('skinpartspecial');
        }
    }

    /**
     * Parse skinvar specialskinlist
     */
    function parse_specialskinlist($templateName = '')
    {
        $templates = array();
        if ($templateName) {
            $templates = skinableTEMPLATE::read($templateName);
        }
        $nType  = array(
            'index',
            'item',
            'error',
            'search',
            'archive',
            'archivelist',
            'imagepopup',
            'member'
        );
        $skinid = intRequestVar('skinid');
        $query  = 'SELECT '
                . '    stype '
                . 'FROM '
                .      sql_table('skin') . ' '
                . 'WHERE '
                . '    stype NOT IN (%s) '
                . 'and sdesc = %d';
        $res    = sql_query(sprintf($query, "'" . implode("', '", $nType) . "'", $skinid));
        if ($res && sql_num_rows($res) > 0) {
            $data = array();
            if (isset($templates['SPECIALSKINLIST_HEAD']) && !empty($templates['SPECIALSKINLIST_HEAD'])) {
                $template['head'] = $templates['SPECIALSKINLIST_HEAD'];
            } else {
                $template['head'] = "<ul>\n";
            }
            echo TEMPLATE::fill($template['head'], $data);
            if (isset($templates['SPECIALSKINLIST_BODY']) && !empty($templates['SPECIALSKINLIST_BODY'])) {
                $template['body'] = $templates['SPECIALSKINLIST_BODY'];
            } else {
                $template['body'] = '<li><a tabindex="<%tabindex%>" href="index.php?action=skinedittype&amp;skinid=<%skinid%>'
                                  . '&amp;type=<%skintype%>"><%skintype%></a> (<a tabindex="<%tabindex%>" href="index.php?'
                                  . 'action=skinremovetype&amp;skinid=<%skinid%>&amp;type=<%skintype%>">remove</a>)</li>';
            }
            $tabstart = 75;
            while ($row = sql_fetch_assoc($res)) {
                $data = array(
                    'tabindex' => $tabstart++,
                    'skinid'   => $skinid,
                    'skintype' => ENTITY::hsc(strtolower($row['stype']), ENT_QUOTES)
                );
                echo TEMPLATE::fill($template['body'], $data);
            }
            $data = array();
            if (isset($templates['SPECIALSKINLIST_FOOT']) && !empty($templates['SPECIALSKINLIST_FOOT'])) {
                $template['foot'] = $templates['SPECIALSKINLIST_FOOT'];
            } else {
                $template['foot'] = "</ul>\n";
            }
            echo TEMPLATE::fill($template['foot'], $data);
        }
    }

    /**
     * Parse skinvar adminspecialskinlist
     */
    function parse_adminspecialskinlist($templateName = '')
    {
        $templates = array();
        if ($templateName) {
            $templates = skinableTEMPLATE::read($templateName);
        }
        $nType  = skinableSKIN::getAdminskinDefaultTypes();
        $skinid = intRequestVar('skinid');
        $query  = 'SELECT '
                . '    stype '
                . 'FROM '
                .      sql_table('adminskin') . ' '
                . 'WHERE '
                . '    stype NOT IN (%s) '
                . 'and sdesc = %d';
        $res    = sql_query(sprintf($query, "'" . implode("', '", $nType) . "'", $skinid));
        if ($res && sql_num_rows($res) > 0) {
            $data = array();
            if (isset($templates['ADMIN_SPECIALSKINLIST_HEAD']) && !empty($templates['ADMIN_SPECIALSKINLIST_HEAD'])) {
                $template['head'] = $templates['ADMIN_SPECIALSKINLIST_HEAD'];
            } else {
                $template['head'] = "<ul>\n";
            }
            echo TEMPLATE::fill($template['head'], $data);
            if (isset($templates['ADMIN_SPECIALSKINLIST_BODY']) && !empty($templates['ADMIN_SPECIALSKINLIST_BODY'])) {
                $template['body'] = $templates['ADMIN_SPECIALSKINLIST_BODY'];
            } else {
                $template['body'] = '<li><a tabindex="<%tabindex%>" href="index.php?action=adminskinedittype&amp;skinid=<%skinid%>'
                                  . '&amp;type=<%skintype%>"><%skintype%></a> (<a tabindex="<%tabindex%>" href="index.php?'
                                  . 'action=adminskinremovetype&amp;skinid=<%skinid%>&amp;type=<%skintype%>">remove</a>)</li>';
            }
            $tabstart = 120;
            while ($row = sql_fetch_assoc($res)) {
                $data = array(
                    'tabindex' => $tabstart++,
                    'skinid'   => $skinid,
                    'skintype' => ENTITY::hsc(strtolower($row['stype']), ENT_QUOTES)
                );
                echo TEMPLATE::fill($template['body'], $data);
            }
            $data = array();
            if (isset($templates['ADMIN_SPECIALSKINLIST_FOOT']) && !empty($templates['ADMIN_SPECIALSKINLIST_FOOT'])) {
                $template['foot'] = $templates['ADMIN_SPECIALSKINLIST_FOOT'];
            } else {
                $template['foot'] = "<ul>\n";
            }
            echo TEMPLATE::fill($template['foot'], $data);
        }
    }

    /**
     * Parse skinvar allowedskinactions
     */
    function parse_allowedskinactions()
    {
        $skinType = strtolower(trim(requestVar('type')));
        $actions  = SKIN::getAllowedActionsForType($skinType);
        sort($actions);
        while ($current = array_shift($actions)) {
            // skip deprecated vars
            if ($current == 'ifcat' || $current == 'imagetext' || $current == 'vars') {
                continue;
            }
            echo helplink('skinvar-' . $current) . "$current</a>";
            if (count($actions) != 0) {
                echo ", ";
            }
        }
    }

    /**
     * Parse skinvar allowedadminskinactions
     */
    function parse_allowedadminskinactions()
    {
        global $CONF;
        $skinType = strtolower(trim(requestVar('type')));
        $actions  = skinableSKIN::getAllowedActionsForType($skinType);
        sort($actions);
        while ($current = array_shift($actions)) {
            // skip deprecated vars
            if ($current == 'ifcat' || $current == 'imagetext' || $current == 'vars') {
                continue;
            }
            echo '<a href="' . $CONF['AdminURL'] . 'adminskins/documentation/help.html#'. $current . '" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); return help(this.href);">' . "$current</a>";
            if (count($actions) != 0) {
                echo ", ";
            }
        }
    }

    /**
     * Parse skinvar skineditallowedlist
     */
    function parse_skineditallowedlist($type, $templateName = '')
    {
        switch ($type) {
            case 'blog':
                $query = 'SELECT '
                       . '    bshortname, '
                       . '    bname '
                       . 'FROM '
                       .      sql_table('blog');
                $show  = array(
                    'content' => 'shortblognames'
                );
                skinableShowlist($query, 'table', $show, $templateName);
                break;
            case 'template':
                $query = 'SELECT '
                       . '    tdname as name, '
                       . '    tddesc as description '
                       . 'FROM '
                       .      sql_table('template_desc');
                $show  = array(
                    'content' => 'shortnames'
                );
                skinableShowlist($query, 'table', $show, $templateName);
                break;
        }
    }

    /**
     * Parse skinvar adminskineditallowedlist
     */
    function parse_adminskineditallowedlist($type = 'template', $templateName = '')
    {
        switch ($type) {
//            case 'blog':
//                $query = 'SELECT '
//                       . '    bshortname, '
//                       . '    bname '
//                       . 'FROM '
//                       .      sql_table('blog');
//                $show  = array(
//                    'content' => 'shortblognames'
//                );
//                skinableShowlist($query, 'table', $show, $templateName);
//                break;
            case 'template':
                $query = 'SELECT '
                       . '    tdname as name, '
                       . '    tddesc as description '
                       . 'FROM '
                       .      sql_table('admintemplate_desc');
                $show  = array(
                    'content' => 'shortnames'
                );
                skinableShowlist($query, 'table', $show, $templateName);
                break;
        }
    }

    /**
     * Parse skinvar defblogselect
     */
    function parse_defblogselect($templateName = '')
    {
        global $CONF;
        $query  = 'SELECT '
                . '    bname   as text, '
                . '    bnumber as value '
                . 'FROM '
                .      sql_table('blog');
        $template['name']     = 'DefaultBlog';
        $template['selected'] = $CONF['DefaultBlog'];
        $template['tabindex'] = 10;
        skinableShowlist($query, 'select', $template, $templateName);
    }

    /**
     * Parse skinvar configsettingsedit
     */
    function parse_configsettingsedit($type)
    {
        global $CONF;
        switch ($type) {
            case 'DefaultListSize':
                if (!array_key_exists('DefaultListSize', $CONF)) {
                    $query = 'INSERT '
                           . 'INTO '
                           .      sql_table('config') . ' '
                           . 'VALUES ('
                           . '    "DefaultListSize", '
                           . '    "10"'
                           . ')';
                    sql_query($query);
                    $CONF['DefaultListSize'] = 10;
                } elseif (intval($CONF['DefaultListSize']) < 1) {
                    $CONF['DefaultListSize'] = 10;
                }
                echo intval($CONF['DefaultListSize']);
                break;
            case 'SessionCookie':
                $value = $CONF['SessionCookie'];
                $txt1  = _SETTINGS_COOKIESESSION;
                $txt2  = _SETTINGS_COOKIEMONTH;
                $this->parse_inputyesno('SessionCookie', $value, 10190, 1, 0, $txt1, $txt2);
                break;
            case 'URLMode':
                $value = $CONF['URLMode'];
                $txt1  = _SETTINGS_URLMODE_NORMAL;
                $txt2  = _SETTINGS_URLMODE_PATHINFO;
                $this->parse_inputyesno('URLMode', $value, 10077, 'normal', 'pathinfo', $txt1, $txt2);
                break;
            default:
                if (isset($CONF[$type]) && is_string($CONF[$type])) {
                    echo  ENTITY::hsc($CONF[$type], ENT_QUOTES);
                }
                break;
        }
    }

    /**
     * Parse skinvar configsettingsyesno
     */
    function parse_configsettingsyesno($type, $tabindex)
    {
        global $CONF;
        if (isset($CONF[$type])) {
            $this->parse_inputyesno($type, $CONF[$type], $tabindex);
        }
    }

    /**
     * Parse skinvar outputspecialdirs
     */
    function parse_outputspecialdirs($type)
    {
        switch ($type) {
            case 'nucleusdir':
                global $DIR_NUCLEUS;
                echo ENTITY::hsc($DIR_NUCLEUS, ENT_QUOTES);
                break;
            case 'mediadir':
                global $DIR_MEDIA;
                echo ENTITY::hsc($DIR_MEDIA, ENT_QUOTES);
                break;
        }
    }

    /**
     * Parse skinvar mediadirwarning
     */
    function parse_mediadirwarning()
    {
        global $DIR_MEDIA;
        if (!is_dir($DIR_MEDIA)) {
            echo "<br /><b>" . _WARNING_NOTADIR . "</b>\n";
        }
        if (!is_readable($DIR_MEDIA)) {
            echo "<br /><b>" . _WARNING_NOTREADABLE . "</b>\n";
        }
        if (!is_writeable($DIR_MEDIA)) {
            echo "<br /><b>" . _WARNING_NOTWRITABLE . "</b>\n";
        }
    }

    /**
     * Parse skinvar jstoolbaroptions
     */
    function parse_jstoolbaroptions()
    {
        global $CONF;
        $options = array(
            _SETTINGS_JSTOOLBAR_NONE,
            _SETTINGS_JSTOOLBAR_SIMPLE,
            _SETTINGS_JSTOOLBAR_FULL
        );
        $i = 1;
        foreach ($options as $option) {
            $text  = '<option value="%d"%s>%s</option>' . "\n";
            $extra = ($CONF['DisableJsTools'] == $i) ? ' selected="selected"' : '';
            echo sprintf($text, $i, $extra, $option);
            $i++;
        }
    }

    /**
     * Parse skinvar systemsettings
     */
    function parse_systemsettings($type = 'phpinfo', $templateName = '')
    {
        global $member, $CONF, $nucleus;
        $member->isAdmin() or $this->objAdmin->disallow();
        $enable  = _ADMIN_SYSTEMOVERVIEW_ENABLE;
        $disable = _ADMIN_SYSTEMOVERVIEW_DISABLE;
        switch ($type) {
            case 'phpversion':
                echo phpversion();
                break;
            case 'sqlserverinfo':
                echo sql_get_server_info();
                break;
            case 'sqlclientinfo':
                echo sql_get_client_info();
                break;
            case 'magicquotesgpc':
                echo ini_get('magic_quotes_gpc') ? 'On' : 'Off';
                break;
            case 'magicquotesruntime':
                echo ini_get('magic_quotes_runtime') ? 'On' : 'Off';
                break;
            case 'registerglobals':
                echo ini_get('register_globals') ? 'On' : 'Off';
                break;
            case 'gdinfo':
                $templates = array();
                if ($templateName) {
                    $templates = skinableTEMPLATE::read($templateName);
                }
                if (isset($templates['SYSTEMINFO_GDSETTINGS']) && !empty($templates['SYSTEMINFO_GDSETTINGS'])) {
                    $template = $templates['SYSTEMINFO_GDSETTINGS'];
                } else {
                    $template = "<tr>\n\t\t" . '<td width="50%">' . "<%key%></td><td><%value%></td>\n</tr>\n";
                }
                $gdinfo = gd_info();
                foreach ($gdinfo as $key => $value) {
                    if (is_bool($value)) {
                        $value = $value ? $enable : $disable;
                    } else {
                        $value = ENTITY::hsc($value, ENT_QUOTES);
                    }
                    $data = array(
                        'key'   => $key,
                        'value' => $value,
                    );
                    echo TEMPLATE::fill($template, $data);
                }
                break;
            case 'modrewrite':
                ob_start();
                phpinfo(INFO_MODULES);
                $im = ob_get_contents();
                ob_end_clean();
                echo (strstr($im, 'mod_rewrite') != '') ? $enable : $disable;
                break;
            case 'nucleusversion':
                echo getNucleusVersion() / 100 . '(' . $nucleus['version'] . ')';
                break;
            case 'nucleuspatchlevel':
                echo getNucleusPatchLevel();
                break;
            case 'confself':
                echo $CONF['Self'];
                break;
            case 'confitemurl':
                echo $CONF['ItemURL'];
                break;
            case 'alertonheaderssent':
                echo $CONF['alertOnHeadersSent'] ? $enable : $disable;
                break;
            case 'nucleuscodename':
                if ($nucleus['codename'] != '') {
                    echo ' &quot;' . $nucleus['codename'] . '&quot;';
                }
                break;
            case 'versioncheckurl':
                echo sprintf(_ADMIN_SYSTEMOVERVIEW_VERSIONCHECK_URL, getNucleusVersion(), getNucleusPatchLevel());
                break;
        }
    }

    /**
     * Parse skinvar bookmarkletadmin
     */
    function parse_bookmarkletadmin($type)
    {
        $blogid = intRequestVar('blogid');
        switch ($type) {
            case 'url':
                echo ENTITY::hsc(getBookmarklet($blogid), ENT_QUOTES);
                break;
            case 'regfile':
                global $manager;
                $url = 'index.php?action=regfile&blogid=' . intval($blogid);
                $url = $manager->addTicketToUrl($url);
                echo ENTITY::hsc($url, ENT_QUOTES, 'SJIS');
                break;
        }
    }

    /**
     * Parse skinvar addtickettourl
     */
    function parse_addtickettourl($url)
    {
        global $manager;
        $url = $manager->addTicketToUrl($url);
        echo ENTITY::hsc($url, ENT_QUOTES, 'SJIS');
    }

    /**
     * Parse skinvar actionloglist
     */
    function parse_actionloglist($templateName = '')
    {
        $query = 'SELECT '
               . '    * '
               . 'FROM '
               .      sql_table('actionlog') . ' '
               . 'ORDER BY '
               . '    timestamp DESC';
        $template['content'] = 'actionlist';
        $amount = skinableShowlist($query, 'table', $template, $templateName);
    }

    /**
     * Parse skinvar pluginlistlist
     */
    function parse_pluginlistlist($templateName = '')
    {
        $query  = 'SELECT '
                . '    * '
                . 'FROM '
                .      sql_table('plugin') . ' '
                . 'ORDER BY '
                . '    porder ASC';
        $template['content']  = 'pluginlist';
        $template['tabindex'] = 10;
        skinableShowlist($query, 'table', $template, $templateName);
    }

    /**
     * Parse skinvar adminbanlist
     */
    function parse_adminbanlist($templateName = '')
    {
        $blogid = intRequestVar('blogid');
        $query  = 'SELECT '
                . '    * '
                . 'FROM '
                .      sql_table('ban') . ' '
                . ' WHERE '
                . '    blogid = ' . $blogid . ' '
                . 'ORDER BY '
                . '    iprange';
        $template['content'] = 'banlist';
        $amount = skinableShowlist($query, 'table', $template, $templateName);
        if ($amount == 0) {
            echo _BAN_NONE;
        }
    }

    /**
     * Parse skinvar requestiprange
     */
    function parse_requestiprange()
    {
        if (requestVar('iprange')) {
            echo ENTITY::hsc(requestVar('iprange'), ENT_QUOTES);
        } elseif (requestVar('ip')) {
            echo ENTITY::hsc(requestVar('ip'), ENT_QUOTES);
        }
    }

    /**
     * Parse skinvar iprangeinput
     */
    function parse_iprangeinput()
    {
        if (requestVar('ip')) {
            $iprangeVal = ENTITY::hsc(requestVar('ip'), ENT_QUOTES);
            echo '<input name="iprange" type="radio" value="' . $iprangeVal . '" checked="checked" id="ip_fixed" />' . "\n";
            echo '<label for="ip_fixed">' . $iprangeVal . "</label><br />\n";
            echo '<input name="iprange" type="radio" value="custom" id="ip_custom" />' . "\n";
            echo '<label for="ip_custom">' . _BAN_IP_CUSTOM . '</label>' . "\n";
            echo '<input name="customiprange" value="' . $iprangeVal . '" maxlength="15" size="15" />' . "\n";
        } else {
            echo '<input name="iprange" value="custom" type="hidden" />' . "\n";
            echo '<input name="customiprange" value="" maxlength="15" size="15" />' . "\n";
        }
    }

    /**
     * Parse skinvar banlistdeletedlist
     */
    function parse_banlistdeletedlist($templateName = '')
    {
        global $manager;
        $templates = array();
        if ($templateName) {
            $templates = skinableTEMPLATE::read($templateName);
        }
        if (isset($templates['BANLIST_DELETED_LIST']) && !empty($templates['BANLIST_DELETED_LIST'])) {
            $template = $templates['BANLIST_DELETED_LIST'];
        } else {
            $template = "<li><%blogname%></li>\n";
        }
        $deleted = requestArray('delblogs');
        foreach ($deleted as $delblog) {
            $blog =& $manager->getBlog($delblog);
            $data =  array(
                ENTITY::hsc($blog->getName(), ENT_QUOTES)
            );
            TEMPLATE::fill($template, $data);
        }
    }

    /**
     * Check exists new plugin
     */
    function _existsNewPlugin()
    {
        global $DIR_PLUGINS;
        $candidates = array();
        $files      = scandir($DIR_PLUGINS);
        foreach ($files as $file) {
            if (preg_match("/^NP_(.*)\.php$/", $file, $matches)) {
                $name = $matches[1];
                $que  = 'SELECT '
                      . '    * '
                      . 'FROM '
                      .      sql_table('plugin') . ' '
                      . 'WHERE '
                      . '    pfile = "NP_' . sql_real_escape_string($name) . '"';
                $res  = sql_query($que);
                if (sql_num_rows($res) == 0) {
                    $candidates[] = $name;
                }
            }
        }
        $this->newPlugCandidates = $candidates;
        return (count($candidates) > 0);
    }

    /**
     * Parse skinvar newpluginlist
     */
    function parse_newpluginlist()
    {
        $candidates = $this->newPlugCandidates;
        foreach ($candidates as $name) {
            echo '<option value="NP_' . $name . '">' . ENTITY::hsc($name) . "</option>\n";
        }
    }

    /**
     * Parse skinvar pluginhelp
     */
    function parse_pluginhelp()
    {
        global $manager, $DIR_PLUGINS;
        $plugid   =  intGetVar('plugid');
        $plugName =  getPluginNameFromPid($plugid);
        $plug     =& $manager->getPlugin($plugName);
        if ($plug->supportsFeature('HelpPage') > 0) {
            $helpfile = $DIR_PLUGINS . $plug->getShortName() . '/help.';
            if (@file_exists($helpfile . 'php')) {
                @include($helpfile . 'php');
                return;
            } elseif (@file_exists($helpfile . 'html')) {
                @include($helpfile . 'html');
                return;
            }
        }
        echo '<p>' . _ERROR . ': ' . _ERROR_PLUGNOHELPFILE . '</p>';
        echo '<p><a href="index.php?action=pluginlist">(' . _BACK . ')</a></p>';
    }

    /**
     * Parse skinvar helpplugname
     */
    function parse_helpplugname()
    {
        $plugid = intGetVar('plugid');
        ENTITY::hsc(getPluginNameFromPid($plugid), ENT_QUOTES);
    }

    /**
     * Parse skinvar editpluginfo
     */
    function parse_editpluginfo($type)
    {
        $pid = intRequestVar('plugid');
        switch ($type) {
            case 'id':
                echo $pid;
                break;
            case 'name':
                echo ENTITY::hsc(getPluginNameFromPid($pid), ENT_QUOTES);
                break;
        }
    }

    /**
     * Parse skinvar geteditpluginfo
     */
    function parse_geteditpluginfo($type)
    {
        $pid = intRequestVar('plugid');
        switch ($type) {
            case 'id':
                return $pid;
                break;
            case 'name':
                return ENTITY::hsc(getPluginNameFromPid($pid), ENT_QUOTES);
                break;
        }
    }

    /**
     * Parse skinvar editplugoptionslist
     */
    function parse_editplugoptionslist($templateName = '')
    {
        global $manager;
        $pid = intRequestVar('plugid');
        $aOptions = array();
        $aOIDs    = array();
        $query    = 'SELECT '
                  . '    * '
                  . 'FROM '
                  .      sql_table('plugin_option_desc') . ' '
                  . 'WHERE '
                  . '    ocontext = "global" '
                  . 'and opid     = ' . $pid . ' '
                  . 'ORDER BY '
                  . '    oid ASC';
        $resource = sql_query($query);
        while ($o = sql_fetch_object($resource)) {
            array_push($aOIDs, $o->oid);
            $aOptions[$o->oid] = array(
                
                'oid'         => $o->oid,
                'value'       => $o->odef,
                'name'        => $o->oname,
                'description' => $o->odesc,
                'type'        => $o->otype,
                'typeinfo'    => $o->oextra,
                'contextid'   => 0
            );
        }
        // fill out actual values
        if (count($aOIDs) > 0) {
            $q = 'SELECT '
               . '    oid, '
               . '    ovalue '
               . 'FROM '
               .      sql_table('plugin_option') . ' '
               . 'WHERE '
               . '    oid in (%s)';
            $d = implode(',', $aOIDs);
            $r = sql_query(sprintf($q, $d));
            while ($o = sql_fetch_object($r)) {
                $aOptions[$o->oid]['value'] = $o->ovalue;
            }
        }

        // call plugins
        $manager->notify(
            'PrePluginOptionsEdit',
            array(
                'context' =>  'global',
                'plugid'  =>  $pid,
                'options' => &$aOptions
            )
        );

        $template['content'] = 'plugoptionlist';
        $amount              = skinableShowlist($aOptions, 'table', $template, $templateName);
        if ($amount == 0) {
            echo '<p>' . _ERROR_NOPLUGOPTIONS . '</p>';
        }
    }

    /**
     * Parse skinvar insertpluginoptions
     */
    function parse_insertpluginoptions($templateName = '')
    {
        $options   = $this->objAdmin->aOptions;
        $template  = array();
        $templats  = array();
        if ($templateName) {
            $templates = skinableTEMPLATE::read($templateName);
        }
        if (isset($templates['INSERT_PLUGOPTION_TITLE']) && !empty($templates['INSERT_PLUGOPTION_TITLE'])) {
            $template['title'] = $templates['INSERT_PLUGOPTION_TITLE'];
        } else  {
            $template['title'] = '<tr><th colspan="2"><%sprinttext(_PLUGIN_OPTIONS_TITLE, <|%insertpluginfo(name)%|>)%></th></tr>' . "\n";
        }
        if (isset($templates['INSERT_PLUGOPTION_BODY']) && !empty($templates['INSERT_PLUGOPTION_BODY'])) {
            $template['body'] = $templates['INSERT_PLUGOPTION_BODY'];
        } else {
            $template['body'] = '<tr><%listplugplugoptionrow%></tr>' . "\n";
        }
        $prevPid = -1;
        foreach ($options as $option) {
            $handler = new skinableACTIONS($this->skintype, $template, $option);
            $parser  = new PARSER(skinableACTIONS::getDefinedActions(), $handler);
            // new plugin?
            if ($prevPid != $option['pid']) {
                $prevPid  = $option['pid'];
                $parser->parse($template['title']);
            }
            $meta = NucleusPlugin::getOptionMeta($option['typeinfo']);
            if (@$meta['access'] != 'hidden') {
                $parsed = $parser->parse($template['body']);
            }
        }
    }

    /**
     * Parse templatevar listplugplugoptionrow
     */
    function parse_listplugplugoptionrow($templateName = '')
    {
        $option = $this->objAdmin;
        echo skinableListplug_plugOptionRow($option, $templateName);
    }

    /**
     * Parse templatevar insertpluginfo
     */
    function parse_insertpluginfo($type)
    {
        $option = $this->objAdmin;
        switch ($type) {
            case 'id':
                return $option['pid'];
                break;
            case 'name':
                return ENTITY::hsc($option['pfile'], ENT_QUOTES);
                break;
        }
    }

    /**
     * Parse templatevar codename
     */
    function parse_codename()
    {
        global $nucleus;
        echo $nucleus['codename'];
    }

    /**
     * Parse skinvar insplugoptcontent
     */
    function parse_insplugoptcontent()
    {
        $option = $this->objAdmin->aOption;
            print_r($option);
        $meta   = NucleusPlugin::getOptionMeta($option['typeinfo']);
        if (isset($meta['access']) && $meta['access'] != 'hidden') {
            echo '<tr>';
            skinableListplug_plugOptionRow($option);
            echo '</tr>';
        }
    }

    /**
     * Parse skinvar adminparsedinclude
     */
    function parse_adminparsedinclude($filename) {
        // check current level
        if ($this->level > 3) return;   // max. depth reached (avoid endless loop)
        $skin = new skinableSKIN($this->skin->id);
        $file = $this->getIncludeFileName($filename);
        if (!$skin->isValid && !file_exists($file)) {
            return;
        }
        $contents = $skin->getContent($filename);
        if (!$contents) {
            if (!file_exists($file)) return;
            $contents = file_get_contents($file);
            if (empty($contents)) return;
        }
        $this->level = $this->level + 1;
        // parse file contents
        $this->parser->parse($contents);

        $this->level = $this->level - 1;
    }

    /**
     * Returns the correct location of the file to be included, according to
     * parser properties
     *
     * IF IncludeMode = 'skindir' => use skindir
     */
    function getIncludeFileName($filename) {
        // leave absolute filenames and http urls as they are
        if (
                (substr($filename,0,1) == '/')
            ||  (substr($filename,0,7) == 'http://')
            ||  (substr($filename,0,6) == 'ftp://')
            )
            return $filename;

        $filename = PARSER::getProperty('IncludePrefix') . $filename;
        if (PARSER::getProperty('IncludeMode') == 'skindir') {
            global $DIR_SKINS;
            return $DIR_SKINS . $filename;
        } else {
            return $filename;
        }
    }

    /**
     * Returns an array with the actions that are defined
     * in the skinableACTIONS class
     */
    static public function getDefinedActions()
    {
        return array(
            'actionloglist',
            'activationmessage',
            'addtickettourl',
            'adminbatchaction',
            'adminbatchlist',
            'adminbanlist',
            'adminbloglink',
            'adminerrormesg',
            'adminparsedinclude',
            'adminskineditallowedlist',
            'adminskinielist',
            'adminskinoverview',
            'adminspecialskinlist',
            'admintemplateoverview',
            'allowedadminskinactions',
            'allowedskinactions',
            'batchmovetitle',
            'batchmovetype',
            'batchmovelist',
            'batchmovebtn',
            'batchdeletelist',
            'batchdeletetype',
            'blogcatlist',
            'blognotifysetting',
            'blogselectbox',
            'blogsettingyesno',
            'blogteamlist',
            'blogteammembers',
            'blogtime',
            'bookmarkletadmin',
            'categorysetting',
            'codename',
            'commentnavlist',
            'configsettingsedit',
            'configsettingsyesno',
            'date',
            'defaultadminskintypes',
            'defblogselect',
            'defcatselect',
            'defskinselect',
            'deletecomment',
            'deleteitemid',
            'deleteitembody',
            'deleteitemtitle',
            'editadminskin',
            'editadminskintype',
            'editadmintemplateinfo',
            'editcomment',
            'editdesturl',
            'editmemberlist',
            'editmember',
            'editskin',
            'editskintype',
            'edittemplateinfo',
            'editpluginfo',
            'editplugoptionslist',
            'extrahead',
            'eventformextra',
            'getblogsetting',
            'geteditpluginfo',
            'headmessage',
            'helplink',
            'helpplugname',
            'ilistaddnew',
            'importskininfo',
            'inputyesno',
            'insertpluginoptions',
            'iprangeinput',
            'itemnavlist',
            'jstoolbaroptions',
            'languageselectoptions',
            'listplugplugoptionrow',
            'mediadirwarning',
            'movedistselect',
            'moveitemid',
            'newmemberselect',
            'newestcompare',
            'newpluginlist',
            'outputspecialdirs',
            'passrequestvars',
            'pluginhelp',
            'pluginlistlist',
            'pluginextras',
            'pluginoptions',
            'qmenuaddselect',
            'quickmenu',
            'requestblogid',
            'requestiprange',
            'selectlocaladminskinfiles',
            'selectlocalskinfiles',
            'skineditallowedlist',
            'skinielist',
            'skinoverview',
            'skintypehelp',
            'specialskinlist',
            'sprinttext',
            'systemsettings',
            'text',
            'templateoverview',
            'ticket',
            'versioncheckurl',
            'yrbloglist',
            'adminstyleselectoptions',
            'adminstyleseets',
            'adminskinselectoptions',
        );
    }

    static function input_yesno($name,
                                $checkedval,
                                $tabindex     = 0,
                                $value1       = 1,
                                $value2       = 0,
                                $yesval       = _YES,
                                $noval        = _NO,
                                $isAdmin      = 0,
                                $templateName = '',
                                $showlist     = false)
    {
        $templates = array();
        if ($templateName) {
            $templates = skinableTEMPLATE::read($templateName);
        }
        if ($name == 'admin') {
            if (isset($templates['INPUTYESNO_TEMPLATE_ADMIN']) && !empty($templates['INPUTYESNO_TEMPLATE_ADMIN'])) {
                $template = $templates['INPUTYESNO_TEMPLATE_ADMIN'];
            } else {
                $template = '<input onclick="selectCanLogin(true);" type="radio" name="<%name%>" value="<%yesval%>"'
                                    . '<%yescheckedval%> id="<%yesid%>" />' . "\n"
                                    . '<label for="<%yesid%>"><%yesvaltext%></label>' . "\n"
                                    . '<input onclick="selectCanLogin(false);" type="radio" name="<%name%>" value="<%noval%>"'
                                    . '<%nocheckedval%> id="<%noid%>"<%disabled%> />' . "\n"
                                    . '<label for="<%noid%>"><%novaltext%></label>' . "\n";
            }
        } else {
            if (isset($templates['INPUTYESNO_TEMPLATE_NORMAL']) && !empty($templates['INPUTYESNO_TEMPLATE_NORMAL'])) {
                $template = $templates['INPUTYESNO_TEMPLATE_NORMAL'];
            }
            if ($showlist) {
                if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OYESNO']) && !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OYESNO'])) {
                    $template = $templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OYESNO'];
                }
            }
            if (!isset($template)) {
                $template = '<input type="radio" name="<%name%>" value="<%yesval%>"'
                                    . '<%yescheckedval%> id="<%yesid%>" />' . "\n"
                                    . '<label for="<%yesid%>"><%yesvaltext%></label>' . "\n"
                                    . '<input type="radio" name="<%name%>" value="<%noval%>"'
                                    . '<%nocheckedval%> id="<%noid%>"<%disabled%> />' . "\n"
                                    . '<label for="<%noid%>"><%novaltext%></label>' . "\n";
            }
        }
        //echo $template;
        $id  = ENTITY::hsc($name, ENT_QUOTES);
        $id  = str_replace('[', '-', $id);
        $id  = str_replace(']', '-', $id);
        $id1 = $id . ENTITY::hsc($value1);
        $id2 = $id . ENTITY::hsc($value2);
        $dat = array(
            'name'          => ENTITY::hsc($name,   ENT_QUOTES),
            'yesval'        => ENTITY::hsc($value1, ENT_QUOTES),
            'noval'         => ENTITY::hsc($value2, ENT_QUOTES),
            'yesid'         => $id1,
            'noid'          => $id2,
            'yesvaltext'    => $yesval,
            'novaltext'     => $noval,
            'yescheckedval' => ($checkedval == $value1) ? ' checked="checked" tabindex="' . $tabindex . '"': '',
            'nocheckedval'  => ($checkedval != $value1) ? ' checked="checked" tabindex="' . $tabindex . '"': '',
            'disabled'      => ($isAdmin && $name == 'canlogin') ? ' disabled="disabled"' : '',
        );
        //$tpl = ($name == 'admin') ? $template['admin'] : $template['normal'];
        if ($showlist) {
            return skinableTEMPLATE::fill($template, $dat);
        } else {
            echo TEMPLATE::fill($template, $dat);
        }
    }





    /**
     *  Forms get parsedincluded now, using an extra <formdata> skinvar
     *
    function doForm($filename) {
        global $DIR_NUCLEUS;
        array_push($this->parser->actions, 'formdata', 'callback', 'errordiv', 'ticket');
        $oldIncludeMode = PARSER::getProperty('IncludeMode');
        $oldIncludePrefix = PARSER::getProperty('IncludePrefix');
        PARSER::setProperty('IncludeMode','normal');
        PARSER::setProperty('IncludePrefix','');
        $this->parse_parsedinclude($DIR_NUCLEUS . 'forms/' . $filename . '.template');
        PARSER::setProperty('IncludeMode',$oldIncludeMode);
        PARSER::setProperty('IncludePrefix',$oldIncludePrefix);
        array_pop($this->parser->actions);      // errordiv
        array_pop($this->parser->actions);      // callback
        array_pop($this->parser->actions);      // formdata
        array_pop($this->parser->actions);      // ticket
    }

    /**
     * Outputs a next/prev link
     *
     * @param $maxresults
     *      The maximum amount of items shown per page (e.g. 10)
     * @param $startpos
     *      Current start position (requestVar('startpos'))
     * @param $direction
     *      either 'prev' or 'next'
     * @param $linktext
     *      When present, the output will be a full <a href...> link. When empty,
     *      only a raw link will be outputted
     *
    function _searchlink($maxresults, $startpos, $direction, $linktext = '') {
        global $CONF, $blog, $query, $amount;
        // TODO: Move request uri to linkparams. this is ugly. sorry for that.
        $startpos   = intval($startpos);        // will be 0 when empty.
        $parsed     = parse_url(serverVar('REQUEST_URI'));
        $parsed     = $parsed['query'];
        $url        = '';

        switch ($direction) {
            case 'prev':
                if ( intval($startpos) - intval($maxresults) >= 0) {
                    $startpos   = intval($startpos) - intval($maxresults);
                    $url        = $CONF['SearchURL'].'?'.alterQueryStr($parsed,'startpos',$startpos);
                }
                break;
            case 'next':
                $iAmountOnPage = $this->amountfound;
                if ($iAmountOnPage == 0)
                {
                    // [%nextlink%] or [%prevlink%] probably called before [%blog%] or [%searchresults%]
                    // try a count query
                    switch ($this->skintype)
                    {
                        case 'index':
                            $sqlquery = $blog->getSqlBlog('', 'count');
                            break;
                        case 'search':
                            $sqlquery = $blog->getSqlSearch($query, $amount, $unused_highlight, 'count');
                            break;
                    }
                    if ($sqlquery)
                        $iAmountOnPage = intval(quickQuery($sqlquery)) - intval($startpos);
                }
                if (intval($iAmountOnPage) >= intval($maxresults)) {
                    $startpos   = intval($startpos) + intval($maxresults);
                    $url        = $CONF['SearchURL'].'?'.alterQueryStr($parsed,'startpos',$startpos);
                }
                break;
            default:
                break;
        } // switch($direction)

        if ($url != '')
            echo $this->_link($url, $linktext);
    }

    /**
     *  Creates an archive link and if no id is given a todaylink 
     *
    function _archivelink($id, $linktext = '') {
        global $CONF, $blog;
        if ($id)
            echo $this->_link(createArchiveLink($blog->getID(), $id, $this->linkparams), $linktext);
        else
            $this->parse_todaylink($linktext);
    }

    /**
     *  Notifies the Manager that a PreBlogContent event occurs
     *
    function _preBlogContent($type, &$blog) {
        global $manager;
        $manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type));
    }

    /**
     *  Notifies the Manager that a PostBlogContent event occurs
     *
    function _postBlogContent($type, &$blog) {
        global $manager;
        $manager->notify('PostBlogContent',array('blog' => &$blog, 'type' => $type));
    }
    
    /**
     * Parse skinvar additemform
     *
    function parse_additemform() {
        global $blog, $CONF;
        $this->formdata = array(
            'adminurl' => ENTITY::hsc($CONF['AdminURL'], ENT_QUOTES),
            'catid' => $blog->getDefaultCategory()
        );
        $blog->InsertJavaScriptInfo();
        $this->doForm('additemform');
    }
    
    /**
     * Parse skinvar addlink
     * A Link that allows to open a bookmarklet to add an item
     *
    function parse_addlink() {
        global $CONF, $member, $blog;
        if ($member->isLoggedIn() && $member->isTeamMember($blog->blogid) ) {
            echo $CONF['AdminURL'].'bookmarklet.php?blogid='.$blog->blogid;
        }
    }

    /**
     * Parse skinvar archive
     *
    function parse_archive($template, $category = '') {
        global $blog, $archive;
        // can be used with either yyyy-mm or yyyy-mm-dd
        sscanf($archive,'%d-%d-%d',$y,$m,$d);
        $this->_setBlogCategory($blog, $category);
        $this->_preBlogContent('achive',$blog);
        $blog->showArchive($template, $y, $m, $d);
        $this->_postBlogContent('achive',$blog);

    }

    /**
     * %archivedate(locale,date format)%
     *
    function parse_archivedate($locale = '-def-') {
        global $archive;

        if ($locale == '-def-')
            setlocale(LC_TIME,$template['LOCALE']);
        else
            setlocale(LC_TIME,$locale);

        // get archive date
        sscanf($archive,'%d-%d-%d',$y,$m,$d);

        // get format
        $args = func_get_args();
        // format can be spread over multiple parameters
        if (sizeof($args) > 1) {
            // take away locale
            array_shift($args);
            // implode
            $format=implode(',',$args);
        } elseif ($d == 0 && $m !=0) {
            $format = '%B %Y';
        } elseif ($m == 0) {
            $format = '%Y';
        } else {
            $format = '%d %B %Y';
        }

        echo strftime($format,mktime(0,0,0,$m?$m:1,$d?$d:1,$y));
    }

    /**
     *  Parse skinvar archivedaylist
     *
    function parse_archivedaylist($template, $category = 'all', $limit = 0) {
        global $blog;
        if ($category == 'all') $category = '';
        $this->_preBlogContent('archivelist',$blog);
        $this->_setBlogCategory($blog, $category);
        $blog->showArchiveList($template, 'day', $limit);
        $this->_postBlogContent('archivelist',$blog);
    }
    
    /**
     *  A link to the archives for the current blog (or for default blog)
     *
    function parse_archivelink($linktext = '') {
        global $blog, $CONF;
        if ($blog)
            echo $this->_link(createArchiveListLink($blog->getID(),$this->linkparams), $linktext);
        else
            echo $this->_link(createArchiveListLink(), $linktext);
    }

    function parse_archivelist($template, $category = 'all', $limit = 0) {
        global $blog;
        if ($category == 'all') $category = '';
        $this->_preBlogContent('archivelist',$blog);
        $this->_setBlogCategory($blog, $category);
        $blog->showArchiveList($template, 'month', $limit);
        $this->_postBlogContent('archivelist',$blog);
    }

    function parse_archiveyearlist($template, $category = 'all', $limit = 0) {
        global $blog;
        if ($category == 'all') $category = '';
        $this->_preBlogContent('archivelist',$blog);
        $this->_setBlogCategory($blog, $category);
        $blog->showArchiveList($template, 'year', $limit);
        $this->_postBlogContent('archivelist',$blog);
    }

    /**
     * Parse skinvar archivetype
     *
    function parse_archivetype() {
        global $archivetype;
        echo $archivetype;
    }

    /**
     * Parse skinvar blog
     *
    function parse_blog($template, $amount = 10, $category = '') {
        global $blog, $startpos;

        list($limit, $offset) = sscanf($amount, '%d(%d)');
        $this->_setBlogCategory($blog, $category);
        $this->_preBlogContent('blog',$blog);
        $this->amountfound = $blog->readLog($template, $limit, $offset, $startpos);
        $this->_postBlogContent('blog',$blog);
    }
    
    /**
     *   Parse skinvar bloglist
     *   Shows a list of all blogs
     *   bnametype: whether 'name' or 'shortname' is used for the link text    
     *   orderby: order criteria
     *   direction: order ascending or descending          
     *
    function parse_bloglist($template, $bnametype = '', $orderby='number', $direction='asc')
    {
        BLOG::showBlogList($template, $bnametype, $orderby, $direction);
    }

    /**
     * Parse categorylist
     *
    function parse_categorylist($template, $blogname = '')
    {
        global $blog, $manager;
        if ($blogname == '') {
            $b =& $blog;
        } else {
            $b =& $manager->getBlog(getBlogIDFromName($blogname));
        }
        $this->_preBlogContent('categorylist',$b);
        $b->showCategoryList($template);
        $this->_postBlogContent('categorylist',$b);
    }

    /**
     * Parse skinvar commentform
     *
    function parse_commentform($destinationurl = '', $templateName = '')
    {
        global $blog, $itemid, $member, $CONF, $manager, $DIR_LIBS, $errormessage;

        // warn when trying to provide a actionurl (used to be a parameter in Nucleus <2.0)
        if (stristr($destinationurl, 'action.php')) {
            $args           = func_get_args();
            $destinationurl = $args[1];
            ACTIONLOG::add(WARNING,_ACTIONURL_NOTLONGER_PARAMATER);
        }
        $actionurl = $CONF['ActionURL'];
        // if item is closed, show message and do nothing
        $item =& $manager->getItem($itemid,0,0);
        if ($item['closed'] || !$blog->commentsEnabled()) {
            $this->doForm('commentform-closed');
            return;
        }
        if (!$destinationurl) {
            $destinationurl = createLink(
                'item',
                array(
                    'itemid'    => $itemid,
                    'title'     => $item['title'],
                    'timestamp' => $item['timestamp'],
                    'extra'     => $this->linkparams
                )
            );
        } else {    // note: createLink returns an HTML encoded URL
            // HTML encode URL
            $destinationurl = ENTITY::hsc($destinationurl, ENT_QUOTES);
        }
        // values to prefill
        $user   = cookieVar($CONF['CookiePrefix'] . 'comment_user');
        $userid = cookieVar($CONF['CookiePrefix'] . 'comment_userid');
        $email  = cookieVar($CONF['CookiePrefix'] . 'comment_email');
        $body   = postVar('body');
        if (!$user) {
            $user   = postVar('user');
        }
        if (!$userid) {
            $userid = postVar('userid');
        }
        if (!$email) {
            $email  = postVar('email');
        }
        $this->formdata = array(
            'itemid'          => $itemid,
            'destinationurl'  => $destinationurl,    // url is already HTML encoded
            'actionurl'       => ENTITY::hsc($actionurl, ENT_QUOTES),
            'user'            => ENTITY::hsc($user,      ENT_QUOTES),
            'userid'          => ENTITY::hsc($userid,    ENT_QUOTES),
            'email'           => ENTITY::hsc($email,     ENT_QUOTES),
            'body'            => ENTITY::hsc($body,      ENT_QUOTES),
            'membername'      => $member->getDisplayName(),
            'rememberchecked' => cookieVar($CONF['CookiePrefix'] . 'comment_user') ? 'checked="checked"' : ''
        );
        if (!$member->isLoggedIn()) {
            $formName = 'commentform-notloggedin';
        } else {
            $formName = 'commentform-loggedin';
        }
        $this->doForm($formName, $templateName);
    }
    
    /**
     * Parse skinvar comments
     * include comments for one item     
     *
    function parse_comments($template) {
        global $itemid, $manager, $blog, $highlight;
        $template =& $manager->getTemplate($template);
        // create parser object & action handler
        $actions  = new ITEMACTIONS($blog);
        $parser   = new PARSER($actions->getDefinedActions(), $actions);
        $actions->setTemplate($template);
        $actions->setParser($parser);
        $item = ITEM::getitem($itemid, 0, 0);
        $actions->setCurrentItem($item);
        $comments = new COMMENTS($itemid);
        $comments->setItemActions($actions);
        $comments->showComments($template, -1, 1, $highlight);  // shows ALL comments
    }
    
    /**
     * Parse ifcat
     *
    function parse_ifcat($text = '')
    {
        if ($text == '') {
            // new behaviour
            $this->parse_if('category');
        } else {
            // old behaviour
            global $catid, $blog;
            if ($blog->isValidCategory($catid)) {
                echo $text;
            }
        }
    }

    /**
     * Parse skinvar item
     * include one item (no comments)    
     *
    function parse_item($template)
    {
        global $blog, $itemid, $highlight;
        $this->_setBlogCategory($blog, ''); // need this to select default category
        $this->_preBlogContent('item', $blog);
        $r = $blog->showOneitem($itemid, $template, $highlight);
        if ($r == 0) {
            echo _ERROR_NOSUCHITEM;
        }
        $this->_postBlogContent('item', $blog);
    }

    /**
     * Parse skinvar membermailform
     *
    function parse_membermailform($rows = 10, $cols = 40, $desturl = '', $templateName = '') {
        global $member, $CONF, $memberid;
        if ($desturl == '') {
            if ($CONF['URLMode'] == 'pathinfo')
                $desturl = createMemberLink($memberid);
            else
                $desturl = $CONF['IndexURL'] . createMemberLink($memberid);
        }
        $message  = postVar('message');
        $frommail = postVar('frommail');
        $this->formdata = array(
            'url'       => ENTITY::hsc($desturl),
            'actionurl' => ENTITY::hsc($CONF['ActionURL'], ENT_QUOTES),
            'memberid'  => $memberid,
            'rows'      => $rows,
            'cols'      => $cols,
            'message'   => ENTITY::hsc($message, ENT_QUOTES),
            'frommail'  => ENTITY::hsc($frommail, ENT_QUOTES)
        );
        if ($member->isLoggedIn()) {
            $this->doForm('membermailform-loggedin', $templateName);
        } elseif ($CONF['NonmemberMail']) {
            $this->doForm('membermailform-notloggedin', $templateName);
        } else {
            $this->doForm('membermailform-disallowed', $templateName);
        }
    }
    
    /**
     * Parse skinvar nextarchive
     *
    function parse_nextarchive() {
        global $archivenext;
        echo $archivenext;
    }

    /**
     * Parse skinvar nextitem
     * (include itemid of next item)
     *
    function parse_nextitem() {
        global $itemidnext;
        if (isset($itemidnext)) {
            echo intval($itemidnext);
        }
    }

    /**
     * Parse skinvar nextitemtitle
     * (include itemtitle of next item)
     *
    function parse_nextitemtitle($format = '') {
        global $itemtitlenext;
        switch ($format) {
            case 'xml':
                echo stringToXML ($itemtitlenext);
                break;
            case 'attribute':
                echo stringToAttribute ($itemtitlenext);
                break;
            case 'raw':
                echo $itemtitlenext;
                break;
            default:
                echo ENTITY::hsc($itemtitlenext, ENT_QUOTES);
                break;
        }
    }

    /**
     * Parse skinvar nextlink
     *
    function parse_nextlink($linktext = '', $amount = 10)
    {
        global $itemidnext, $archivenext, $startpos;
        if ($this->skintype == 'item') {
            $this->_itemlink($itemidnext, $linktext);
        } elseif ($this->skintype == 'search' || $this->skintype == 'index') {
            $this->_searchlink($amount, $startpos, 'next', $linktext);
        } else {
            $this->_archivelink($archivenext, $linktext);
        }
    }

    /**
     * Parse skinvar otherarchive
     *
    function parse_otherarchive($blogname, $template, $category = '')
    {
        global $archive, $manager;
        sscanf($archive,'%d-%d-%d',$y,$m,$d);
        $b =& $manager->getBlog(getBlogIDFromName($blogname));
        $this->_setBlogCategory($b, $category);
        $this->_preBlogContent('otherachive',$b);
        $b->showArchive($template, $y, $m, $d);
        $this->_postBlogContent('otherachive',$b);
    }

    /**
     * Parse skinvar otherarchivedaylist
     *
    function parse_otherarchivedaylist($blogname, $template, $category = 'all', $limit = 0) {
        global $manager;
        if ($category == 'all') $category = '';
        $b =& $manager->getBlog(getBlogIDFromName($blogname));
        $this->_setBlogCategory($b, $category);
        $this->_preBlogContent('otherarchivelist',$b);
        $b->showArchiveList($template, 'day', $limit);
        $this->_postBlogContent('otherarchivelist',$b);
    }
    
    /**
     * Parse skinvar otherarchivelist
     *
    function parse_otherarchivelist($blogname, $template, $category = 'all', $limit = 0) {
        global $manager;
        if ($category == 'all') $category = '';
        $b =& $manager->getBlog(getBlogIDFromName($blogname));
        $this->_setBlogCategory($b, $category);
        $this->_preBlogContent('otherarchivelist',$b);
        $b->showArchiveList($template, 'month', $limit);
        $this->_postBlogContent('otherarchivelist',$b);
    }

    /**
     * Parse skinvar otherarchiveyearlist
     *
    function parse_otherarchiveyearlist($blogname, $template, $category = 'all', $limit = 0) {
        global $manager;
        if ($category == 'all') $category = '';
        $b =& $manager->getBlog(getBlogIDFromName($blogname));
        $this->_setBlogCategory($b, $category);
        $this->_preBlogContent('otherarchivelist',$b);
        $b->showArchiveList($template, 'year', $limit);
        $this->_postBlogContent('otherarchivelist',$b);
    }

    /**
     * Parse skinvar otherblog
     *
    function parse_otherblog($blogname, $template, $amount = 10, $category = '') {
        global $manager;

        list($limit, $offset) = sscanf($amount, '%d(%d)');

        $b =& $manager->getBlog(getBlogIDFromName($blogname));
        $this->_setBlogCategory($b, $category);
        $this->_preBlogContent('otherblog',$b);
        $this->amountfound = $b->readLog($template, $limit, $offset);
        $this->_postBlogContent('otherblog',$b);
    }

    /**
     * Parse skinvar othersearchresults
     *
    function parse_othersearchresults($blogname, $template, $maxresults = 50) {
        global $query, $amount, $manager, $startpos;
        $b =& $manager->getBlog(getBlogIDFromName($blogname));
        $this->_setBlogCategory($b, '');    // need this to select default category
        $this->_preBlogContent('othersearchresults',$b);
        $b->search($query, $template, $amount, $maxresults, $startpos);
        $this->_postBlogContent('othersearchresults',$b);
    }

    /**
     * Parse skinvar prevarchive
     *
    function parse_prevarchive() {
        global $archiveprev;
        echo $archiveprev;
    }

    /**
     * Parse skinvar preview
     *
    function parse_preview($template) {
        global $blog, $CONF, $manager;
        $template       =& $manager->getTemplate($template);
        $row['body']     = '<span id="prevbody"></span>';
        $row['title']    = '<span id="prevtitle"></span>';
        $row['more']     = '<span id="prevmore"></span>';
        $row['itemlink'] = '';
        $row['itemid']   = 0; $row['blogid'] = $blog->getID();
        echo TEMPLATE::fill($template['ITEM_HEADER'],$row);
        echo TEMPLATE::fill($template['ITEM'],$row);
        echo TEMPLATE::fill($template['ITEM_FOOTER'],$row);
    }

    /*
     * Parse skinvar previtem
     * (include itemid of prev item)
     *
    function parse_previtem() {
        global $itemidprev;
        if (isset($itemidprev)) echo (int)$itemidprev;
    }

    /**
     * Parse skinvar previtemtitle
     * (include itemtitle of prev item)
     *
    function parse_previtemtitle($format = '') {
        global $itemtitleprev;
        switch ($format) {
            case 'xml':
                echo stringToXML ($itemtitleprev);
                break;
            case 'attribute':
                echo stringToAttribute ($itemtitleprev);
                break;
            case 'raw':
                echo $itemtitleprev;
                break;
            default:
                echo ENTITY::hsc($itemtitleprev, ENT_QUOTES);
                break;
        }
    }

    /**
     * Parse skinvar prevlink
     *
    function parse_prevlink($linktext = '', $amount = 10) {
        global $itemidprev, $archiveprev, $startpos;

        if ($this->skintype == 'item') {
            $this->_itemlink($itemidprev, $linktext);
        } elseif ($this->skintype == 'search' || $this->skintype == 'index') {
            $this->_searchlink($amount, $startpos, 'prev', $linktext);
        } else {
            $this->_archivelink($archiveprev, $linktext);
        }
    }

    /**
     * Parse skinvar searchresults
     *
    function parse_searchresults($template, $maxresults = 50 ) {
        global $blog, $query, $amount, $startpos;
        $this->_setBlogCategory($blog, ''); // need this to select default category
        $this->_preBlogContent('searchresults', $blog);
        $this->amountfound = $blog->search($query, $template, $amount, $maxresults, $startpos);
        $this->_postBlogContent('searchresults', $blog);
    }

    /**
     *  Parse skinvar todaylink
     *  A link to the today page (depending on selected blog, etc...)
     *
    function parse_todaylink($linktext = '') {
        global $blog, $CONF;
        if ($blog) {
            echo $this->_link(createBlogidLink($blog->getID(),$this->linkparams), $linktext);
        } else {
            echo $this->_link($CONF['SiteUrl'], $linktext);
        }
    }

    /**
     * Parse vars
     * When commentform is not used, to include a hidden field with itemid   
     *
    function parse_vars() {
        global $itemid;
        echo '<input type="hidden" name="itemid" value="' . $itemid . '" />';
    }

    /**
     * Parse skinvar sticky
     *
    function parse_sticky($itemnumber = 0, $template = '') {
        global $manager;
        $itemnumber = intval($itemnumber);
        $itemarray  = array($itemnumber);
        $b =& $manager->getBlog(getBlogIDFromItemID($itemnumber));
        $this->_preBlogContent('sticky', $b);
        $this->amountfound = $b->readLogFromList($itemarray, $template);
        $this->_postBlogContent('sticky', $b);
    }
/**/




}




/**
 * This is the parser class of Nucleus. It is used for various things (skin parsing,
 * form generation, ...)
 */
class skinablePARSER
{

    // array with the names of all allowed actions
    var $actions;

    // reference to actions handler
    var $handler;

    // delimiters that can be used for skin/templatevars
    var $delim;

    // parameter delimiter (to separate skinvar params)
    var $pdelim;

    // usually set to 0. When set to 1, all skinvars are allowed regardless of $actions
    var $norestrictions;

    /**
     * Creates a new parser object with the given allowed actions
     * and the given handler
     *
     * @param $allowedActions array
     * @param $handler class object with functions for each action (reference)
     * @param $delim optional delimiter
     * @param $paramdelim optional parameterdelimiter
     */
    function __construct(&$handler) {
        $this->actions = skinableACTIONS::getDefinedActions();
        $this->handler =& $handler;
        $this->delim   = '(<%|%>)';
        $this->pdelim  = ', ';
        $this->norestrictions = 0;
    }

    /**
     * Parses the given contents and outputs it
     */
    function parse(&$contents) {

        $pieces = preg_split('/'.$this->delim.'/',$contents);

        $maxidx = sizeof($pieces);
        for ($idx = 0; $idx < $maxidx; $idx++) {
            echo $pieces[$idx];
            $idx++;
            if ($idx < $maxidx) {
                $this->doAction($pieces[$idx]);
            }
        }
    }

    /**
     * handle an action
     */
    function doAction($action) {
        global $manager, $CONF;

        if (!$action) return;

        if (strstr($action,'(')) {
            $paramStartPos = strpos($action, '(');
            $actionParams  = substr($action, $paramStartPos + 1, strlen($action) - $paramStartPos - 2);
            $actionRaw     = substr($action, 0, $paramStartPos);
            $actionParams  = explode ($this->pdelim, $actionParams);
            $actionParams  = array_map('trim',$actionParams);
        } else {
            $actionParams = array();
            $actionRaw    = $action;
        }

        $actionlc = strtolower($actionRaw);

        if (!$this->handler->if_currentlevel && ($actionlc != 'else') && ($actionlc != 'elseif') && ($actionlc != 'endif') && ($actionlc != 'ifnot') && ($actionlc != 'elseifnot') && (substr($actionlc,0,2) != 'if'))
            return;

        $out = '';
        if (in_array($actionlc, $this->actions) || $this->norestrictions ) {
            ob_start();
            call_user_func_array(array(&$this->handler, 'parse_' . $actionlc), $actionParams);
            $out = ob_get_contents();
            ob_end_clean();
        } else {
            if (in_array('plugin', $this->actions) && $manager->pluginInstalled('NP_' . $actionRaw)) {
                $this->doAction('plugin(' . $action . ')');
            }
        }
        if (!$out) {
            echo '<%' . $action . '%>';
        } else {
            echo $out;
        }
    }

}
